Jump to content

My sql query is giving me a wrong result


prolife
Go to solution Solved by prolife,

Recommended Posts

hello people my code is displaying the last result instead of the exact result i requested for.

Here is my code

 

 

<table width="800" height="40" align="center">
               <form action="admin-edit-room.php" method="post">
              <?php
                  $object->database();
                  $object->set_sqlstr(htmlspecialchars( "SELECT `cat`.*,`rooms`.* FROM `cat`,`rooms` WHERE `cat`.`id` = `rooms`.`catid`  ") );
                 // $object->set_sqlstr("SELECT * FROM `rooms` " );
                  $object->querydata();
                  $num = $object->no_rows;
                  if($num=0){echo "Your inbox is empty";}
                  $i=1;
                  while($object->data[0]!= ""){  
                      $class = (($i%2)==0) ? 'td_colour1' : 'td_colour2';
                      echo'<tr class="'.$class.'">';
                        echo'<td width="50" height="10" class="admin-details-form" align="left">'. $object->data['room-name'] .'</td>';
                        echo'<td width="200" height="10" class="admin-details-form" align="left">'. $object->data['room-descript'] .'</td>';
                        echo'<td width="200" height="10" class="admin-details-form" align="left"><input type="hidden" name="roomid" value="'.$object->data['roomid'].'" />'.$object->data['catid'].'</td>';
                        echo'<td width="200" height="10" class="admin-details-form" align="left"><input type="hidden" name="catid" value="'.$object->data['catid'].'" /></td>';
                        echo'<td width="10" height="10" class="admin-details-form" align="center"><input type="submit" name="edit" value="Edit" /></td>';
                      echo'</tr>';
                      
                    $object->fetchdata();
                    $i++;
                }
              ?>   
               </form>
            </table>

 

Now the thing is i placed "roomid" inside an hidden field and submited it to the next  transaction page as you can see but instead of it submiting the specific id it keeps submiting the last roomid, please what could be the problem? thanks

Link to comment
Share on other sites

$object->set_sqlstr(htmlspecialchars( "SELECT `cat`.*,`rooms`.* FROM `cat`,`rooms` WHERE `cat`.`id` = `rooms`.`catid`  ") );
There's no HTML in there. Don't use htmlspecialchars().

 

SELECT `cat`.*,`rooms`.* 
Don't SELECT * when you only want a couple columns. Specifically name the ones you want.

 

$object->no_rows
Is it really called "no_rows"? Not, like, "num_rows"?

 

if($num=0){
Not enough =s.

 

$object->data['room-name']
Is it really named with a hyphen? If so, that better be because the $object thing added it and not because your column is actually named "room-name".

 

it keeps submiting the last roomid

Are you sure that is what's happening? Have you verified that the HTML you've outputted has the wrong ID there?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.