SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: confusing ..

  1. #1
    SitePoint Addict joyce's Avatar
    Join Date
    Aug 2001
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    confusing ..

    i have select out a record from a table 1 and plan to display out the record.

    in order to display out the record, i have to go through this if statement. so if the variable fits the conditon, it will go to another table and select out another record from table 2.

    then finally display out the record.

    my problem now is, the things that i want to display is from table 1 not table 2. but somehow it will display record from table 1. pls help.

    below are my codes:

    table 1:
    <hr>
    $table = "cat_review";
    $field = "*";
    $criteria = "where cat_cat='$cat' ";
    if ($subcat != '')
    $criteria .= " and cat_subcat='$subcat' ";
    $criteria .= "order by ID desc";
    $getdata=$review_obj->get_data($table, $field, $criteria);
    $data=$getdata[0];
    $numrows=$getdata[1];

    if ($numrows > 0)
    {
    for ($i=0; $i < $numrows; $i++)
    {
    $id = $data[$i][0];
    $cat = $data[$i][1];
    $subcat = $data[$i][2];
    $title = $data[$i][3];
    $desc = $data[$i][4];
    $image = $data[$i][5];
    <hr>

    if statement and table 2:
    <hr>
    if ($mid != 1) {

    $table = "cat_review";
    $field = "mod_ID";
    $criteria = "where mod_ID='$mid'";

    $getdata=$review_obj -> get_data($table,$field,$criteria);
    $data=$getdata[0];
    $numrows=$getdata[1];
    <hr>

    records that i want to display from table 1:
    <hr>
    echo "<font face=verdana size=1><a href=\"edit_mod_main.php?id=".$data[$i][0]."&cat=".$data[$i][1]."&subcat=".$data[$i][2]."&title=".$data[$i][3]."&desc=".$data[$i][4]."&flag=$flag\">Edit</a>&nbsp;|&nbsp;</font>";
    echo "<font face=verdana size=1><a href=\"edit_admin_img.php?id=".$data[$i][0]."&flag=$flag\">Edit Image</a></font>";
    }
    echo "</table>";
    <hr>

  2. #2
    SitePoint Enthusiast numeropi's Avatar
    Join Date
    Apr 2001
    Location
    somewhere between 3.14 and 3.15
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you are overwriting your variables.

    In the code for table1 you have

    Code:
    $data=$getdata[0]; 
    $numrows=$getdata[1];
    so now, $data contains your data from table1. However, in the code for table2 you also have

    Code:
    $data=$getdata[0]; 
    $numrows=$getdata[1];
    so by the time you reach the code where you print the records, $data contains data from table2.

    Solution: in the code for table2, use $data2 instead of $data and $numrows2 instead of $numrows

    I'm still learning PHP so I may well be wrong... but give it a try

  3. #3
    SitePoint Addict joyce's Avatar
    Join Date
    Aug 2001
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are right. i overwrite my variables. but i found another problem. when the if statement is true, it should display 3 links(which is write a review, edit, edit image) but it only display one link(write a review). pls help.

    the code:

    if ($flag == md5(2))
    {

    echo "<div align=right><font face=verdana size=1><a href =\" http://www.certifyexpress.com/review...eview.php?gid=$id&cat=$cat&title=$title&subcat=$subcat\">Write a review</a></font>";


    $table = "cat_review";
    $field = "*";
    $criteria = "where mod_ID='$mid' and cat_cat='$cat'";

    $getdata=$review_obj -> get_data($table,$field,$criteria);
    $data1=$getdata[0];

    if ($num > 0)
    {


    echo "<font face=verdana size=1>&nbsp;|&nbsp;<a href=\"edit_mod_main.php?id=".$data[$i][0]."&cat=".$data[$i][1]."&subcat=".$data[$i][2]."&title=".$data[$i][3]."&desc=".$data[$i][4]."&flag=$flag\">Edit</a>&nbsp;|&nbsp;</font>";
    echo "<font face=verdana size=1><a href=\"edit_admin_img.php?id=".$data[$i][0]."&flag=$flag\">Edit Image</a></font>";

    }
    echo "</table>";
    }

  4. #4
    SitePoint Enthusiast numeropi's Avatar
    Join Date
    Apr 2001
    Location
    somewhere between 3.14 and 3.15
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when the if statement is true, it should display 3 links(which is write a review, edit, edit image) but it only display one link(write a review).
    I suppose you are referring to the first if statement in your code,

    Code:
    if ($flag == md5(2))
    The other links depend on $num to be greater than 0 to be printed


    Code:
    if ($num > 0) 
    { 
    
    
    echo "<font face=verdana size=1> | <a href=\"edit_mod_main.php?id=".$data[$i][0]."&cat=".$data[$i][1]."&subcat=".$data[$i][2]."&title=".$data[$i][3]."&desc=".$data[$i][4]."&flag=$flag\">Edit</a> | </font>"; 
    echo "<font face=verdana size=1><a href=\"edit_admin_img.php?id=".$data[$i][0]."&flag=$flag\">Edit Image</a></font>"; 
    
    }
    but I don't see where you set $num in your code,
    so this might be the problem. Try removing the
    if ($num > 0) { } if you don't know what it's doing there. Otherwise, if you know that printing the last two links must depend on $num being greater than zero, check where you are setting $num

  5. #5
    SitePoint Addict joyce's Avatar
    Join Date
    Aug 2001
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i forgot to put:

    $num=$getdata[1];

    before the :
    if ($num > 0)


    now everything is ok already.

    Thanks, numeropi!!

  6. #6
    SitePoint Enthusiast numeropi's Avatar
    Join Date
    Apr 2001
    Location
    somewhere between 3.14 and 3.15
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome


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
  •