SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Zealot GHicks's Avatar
    Join Date
    Oct 2003
    Location
    Prescott Valley, Arizona, United States
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Iterate through result set

    OK, I'm sure I'm being blind again and missing something obvious, but i can't figure out what.

    I am running a query against my DB and it is returning 0 results, even though when I run the query directly against the database using my DB admin panel it returns exactly what I expect it to.

    Here is my code:

    <?php
    include_once('../inc_dbconnect.inc');
    $GetCategories = "SELECT ID, Category FROM Work_Categories WHERE Active = '1'";
    $GetCatResult = mysqli_query($db_server, $GetCategories)
    or die("Unable to run query: " . mysqli_error($db_server));
    $NumResults = mysqli_num_rows($GetCatResult);
    echo $NumResults;
    while($Category = mysqli_fetch_array($GetCatResult))
    {
    if ($Category['ID'] == $EmpDetails['workcatid'])
    {
    echo "<option value='" . $Category['ID'] . "' selected=\"selected\">" . $Category['Category'] . "</option>" . "\n";
    } else {
    echo "<option value='" . $Category['ID'] . "'>" . $Category['Category'] . "</option>" . "\n";
    }
    }
    ?>

    The $NumResults and subsequent echo statement I just put in trying to see what I am returning and it shows me 0. There should be about 10 records returned that I want to use to populate a dropdown field on my website.

    Hopefully someone can give me that gently nudge (or a hard smack) to get me back on the right track.

    Greg

  2. #2
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this line to see if your query runs successfully,
    PHP Code:
    $GetCatResult mysqli_query($GetCategories) or die("Unable to run query: " mysqli_error($GetCategories)); 

  3. #3
    SitePoint Zealot GHicks's Avatar
    Join Date
    Oct 2003
    Location
    Prescott Valley, Arizona, United States
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, got these errors when I changed those values:

    Warning: mysqli_query() expects at least 2 parameters, 1 given in /var/www/vhosts/mysite.com/httpdocs/myapp/includes/inc_catdropdown.inc on line 4

    Warning: mysqli_error() expects parameter 1 to be mysqli, string given in /var/www/vhosts/mysite.com/httpdocs/myapp/includes/inc_catdropdown.inc on line 5
    Unable to run query:

  4. #4
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then the old should be fine,
    PHP Code:
    $GetCatResult mysqli_query($db_server$GetCategories) or die("Unable to run query: " mysqli_error($db_server)); 
    Are you sure that there are records which are active?

  5. #5
    SitePoint Zealot GHicks's Avatar
    Join Date
    Oct 2003
    Location
    Prescott Valley, Arizona, United States
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, I take that EXACT query (cut/paste) and run it in HeidiSQL linked to the same database... CRAP! HeidiSQL is linking to my LIVE database, NOT me dev one. See? I knew it was me being stupid!
    Greg

  6. #6
    SitePoint Zealot GHicks's Avatar
    Join Date
    Oct 2003
    Location
    Prescott Valley, Arizona, United States
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sheesh! Maybe it's time to call it a night. No results happens when you have failed to populate your development database with real data! Sheer BRILLIANCE on my part!
    Thanks again for the gentle slap upside the head, I promise I'll quit for the night.
    Greg

  7. #7
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can include this;

    $mysqli =mysqli_connect($server,$username,$password,$database);

    you are not create an instance of the connection to the database...

    And then execute query like this:::

    $result=mysqli_query($mysqli,"your query");

  8. #8
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by venkat6134 View Post
    You can include this;

    $mysqli =mysqli_connect($server,$username,$password,$database);

    you are not create an instance of the connection to the database...

    And then execute query like this:::

    $result=mysqli_query($mysqli,"your query");
    Included file,
    include_once('../inc_dbconnect.inc');


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •