#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Seattle, WA USA
    Posts
    23
    Rep Power
    0
    I have written a function to bulid a table of url links stored in MySQL. In my database I have two tables: tblLinkTypes and tblLinks. My Output should look like this:

    Link Type1
    Link Title2 URL2

    Link Type2
    Link Title1 URL1


    However I get this error when the code gets to the bottom (see //errors here).
    Warning: 4 is not a MySQL result index in /home/httpd/inc/dbWhiteWater.inc on line 275

    Here is my function:
    Function DisplayLinks() {
    $q = new DB_WhiteWater;
    $sel_q = "SELECT * FROM tblLinkTypes ORDER BY SortOrder";
    $result = $q->query($sel_q);
    if ($myrow = mysql_fetch_array($result)) {
    do {
    $title = $myrow["TypeName"];
    $SearchValue = $myrow["TypeKey"];
    $sel_q2 = "SELECT * FROM tblLinks WHERE LinkType ";
    $sel_q2 .= "LIKE '%" .$SearchValue."%'";
    $sel_q2 .= "ORDER BY Title";
    $result2 = $q->query($sel_q2);

    echo("<H2>".$title."</H2>");
    if ($myrow2 = mysql_fetch_array($result2)) {
    echo("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 WIDTH='100%'>n");
    echo("<TR BGCOLOR='#9abcde6'>n");
    echo("<TD WIDTH='30%'>Name</TD><TD WIDTH='70%'>URL</TD>n");
    echo("</TR>n");

    do {
    $url = $myrow2["LinkURL"];
    $name = $myrow2["Title"];
    echo("<TR><TD>n");
    echo($name."</TD>n");
    echo("<TD><A HREF='http://".$url."' target=_new>".$url."</A></TD></TR>n");
    } while ($myrow2 = mysql_fetch_array($result2));
    mysql_free_result ($result2);
    echo("</TABLE>n");
    } else {
    echo("No Entries");
    }
    } while ($myrow = mysql_fetch_array($result)); //errors here
    mysql_free_result ($result); //errors here
    }
    }// end build links
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    Warning: 4 is not a MySQL result index in /home/httpd/inc/dbWhiteWater.inc on line 275
    >>

    This means your table field name which you given in your script is wrong.check it out your table field name with the name you given in your script(ie,...$title = $myrow["TypeName"].....)


    other things are ok..

    try the following script..

    Function DisplayLinks() {
    $q = new DB_WhiteWater;
    $sel_q = "SELECT * FROM tblLinkTypes ORDER BY SortOrder";
    $result = $q->query($sel_q);
    if (mysql_num_rows($result)>0) {
    do {
    $title = $myrow["TypeName"];
    $SearchValue = $myrow["TypeKey"];
    $sel_q2 = "SELECT * FROM tblLinks WHERE LinkType ";
    $sel_q2 .= "LIKE '%" .$SearchValue."%'";
    $sel_q2 .= "ORDER BY Title";
    $result2 = $q->query($sel_q2);

    echo("<H2>".$title."</H2>");

    if (mysql_num_rows($result2)>0) {
    echo("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 WIDTH='100%'>n");
    echo("<TR BGCOLOR='#9abcde6'>n");
    echo("<TD WIDTH='30%'>Name</TD><TD WIDTH='70%'>URL</TD>n");
    echo("</TR>n");

    do {
    $url = $myrow2["LinkURL"];
    $name = $myrow2["Title"];
    echo("<TR><TD>n");
    echo($name."</TD>n");
    echo("<TD><A HREF='http://".$url."' target=_new>".$url."</A></TD></TR>n");
    } while ($myrow2 = mysql_fetch_array($result2));

    mysql_free_result ($result2);
    echo("</TABLE>n");
    } else {
    echo("No Entries");
    }
    } while ($myrow = mysql_fetch_array($result)); //errors here
    mysql_free_result ($result); //errors here
    }
    }// end build links


    Good Luck!!!


    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Seattle, WA USA
    Posts
    23
    Rep Power
    0
    Thanks for your input... the script didn't fix the problem :-( I checked my field names...they are correct:

    tblLinkTypes tblLinks
    TypeKey LinkURL
    TypeName Title
    SortOrder LinkType

    Here is the link to the page: www.nwkayaking.com/NewLinks.php3

  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Austin, TX, USA
    Posts
    11
    Rep Power
    0
    Do you think you could indicate which line is the line number where the error came from?

    ------------------
    Dave Bryant
    dbryant@jump.net
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Seattle, WA USA
    Posts
    23
    Rep Power
    0
    In the first sample code, near the bottom I've noted the erroring lines with notation. Thanks for any help :-)

    Carl
  10. #6
  11. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    try to use column index insted of column name in your script and see how it works.
    also comment second do{}while loop for debugging purpose.


    Function DisplayLinks() {
    $q = new DB_WhiteWater;
    $sel_q = "SELECT * FROM tblLinkTypes ORDER BY SortOrder";
    $result = $q->query($sel_q);
    if (mysql_num_rows($result)>0) {
    do {
    $title = $myrow[0];
    $SearchValue = $myrow[1];
    $sel_q2 = "SELECT * FROM tblLinks WHERE LinkType ";
    $sel_q2 .= "LIKE '%" .$SearchValue."%'";
    $sel_q2 .= "ORDER BY Title";
    $result2 = $q->query($sel_q2);

    echo("<H2>".$title."</H2>");

    if (mysql_num_rows($result2)>0) {
    echo("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 WIDTH='100%'>n");
    echo("<TR BGCOLOR='#9abcde6'>n");
    echo("<TD WIDTH='30%'>Name</TD><TD WIDTH='70%'>URL</TD>n");
    echo("</TR>n");

    /*
    do {
    $url = $myrow2[0];
    $name = $myrow2[1];
    echo("<TR><TD>n");
    echo($name."</TD>n");
    echo("<TD><A HREF='http://".$url."' target=_new>".$url."</A></TD></TR>n");
    } while ($myrow2 = mysql_fetch_array($result2));

    mysql_free_result ($result2);
    */

    echo("</TABLE>n");


    } else {
    echo("No Entries");
    }
    } while ($myrow = mysql_fetch_array($result)); //errors here
    mysql_free_result ($result); //errors here
    }
    }// end build links


    One more suggession, try to print '$sel_q2' query in side the loop and see how it is producing the sql query.also unset that variable before end of the while loop(ie,unset($sel_q2)).



    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Seattle, WA USA
    Posts
    23
    Rep Power
    0
    Thanks...Debugging rule number one...comment out one line at a time to find the culprit. I found mine: $result2 = $q->query($sel_q2);

    My fix: I declared a new variable:
    $q2 = new dbWhitewater;
    $result2 = $q2->query($sel_q2);

    Thanks for all your input...I didn't realize that reusing q$ would cause a problem...I assumed the record set would be held in $result.


    Carl Sweetland
  14. #8
  15. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    My fix: I declared a new variable:
    $q2 = new dbWhitewater;
    $result2 = $q2->query($sel_q2);
    >>


    Great!!



    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. Codepupil
    By Adachic in forum C Programming
    Replies: 3
    Last Post: February 6th, 2004, 07:50 PM
  2. syntax error : identifer 'Hole'
    By bootrecker in forum C Programming
    Replies: 2
    Last Post: February 2nd, 2004, 09:08 AM
  3. Replies: 4
    Last Post: January 28th, 2004, 09:29 AM
  4. mysql: getting error description from error code
    By laker in forum PHP Development
    Replies: 1
    Last Post: January 21st, 2004, 07:03 AM
  5. I don't know what this error message means
    By lcham02 in forum Java Help
    Replies: 2
    Last Post: January 13th, 2004, 12:57 PM

IMN logo majestic logo threadwatch logo seochat tools logo