Jump to content

**SOLVED** Querying database


me1000

Recommended Posts

ok i have a bit of a problem...

im using the following code to query the database, first it searchs for the cat, and then it will see if the can is aproved. 1 being yes, 0 being no.

[code]<?

$inCatID       = (is_numeric($_REQUEST['cat'])) ? $_REQUEST['cat'] : 1;

    $query = "SELECT ID, TUT_TITLE, AUTHOR FROM $sTableName WHERE TUT_CAT=$inCatID AND APROVED = 1";
?>
[/code]

please tell me if that code is messed up at all!

its grabbing the ID, TUT_TITLE, and AUTHOR fields from the database table.
______________________________________________________________________

now im using a while loop to display teh results. this is messy!!!

[code]<table width="100%" border="0">
            <tr>
              <td width="50%"><font size="2">Tutorial Title </font></td>
              <td width="50%"><font size="2">Tutorial Author </font></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
          <?
// get count of rows returned by query
if (mysql_num_rows($query) > 0) {

     while($r=mysql_fetch_array($query))
{    

    
    $tut_title = $_CONTENT['TUT_TITLE'];
    
    $tut_author = $_CONTENT['AUTHOR'];
    
    $tut_id = $_CONTENT['ID'];
    
    $link = '<a href ="view_tuts.php?id='.$tut_id.'">'.$tut_title.'</a>';
    
    $author_link = '<a href ="userinfo.php?user='.$tut_author.'">'.$tut_author.'</a>';
    
echo "
<tr>
<td width=50%><font size='2'>". $link."</font></td>
<td width=50%><font size='2'>". $author_link."</font></td>
</tr>";

}
      }
else {

       echo "<tr>
       <td colspan='2'>
       No tutorials Found!
       </td>
       </tr>";
}
          
           ?>
</table>[/code]

I have an entry in the database that matches what the query is looking for but im getting No Tutorials Found!

Please help!

-Thanks
Link to comment
https://forums.phpfreaks.com/topic/10917-solved-querying-database/
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$query = "SELECT ID, TUT_TITLE, AUTHOR FROM $sTableName WHERE TUT_CAT=$inCatID AND APROVED = 1";[/quote]

That defines the query but you have to execute it.

Try

[code]$querySQL = "SELECT ID, TUT_TITLE, AUTHOR FROM $sTableName WHERE TUT_CAT=$inCatID AND APROVED = 1";

$query = mysql_query($querySQL) or die (mysql_error() . '<br> in : <br>'' . $querySQL);[/code]

If it is messed up, you will get the error message telling you why and the query string will be echoed'
ok, Thanks for that. now I want them in ASC order.
so that the last row of the database displays first.
[code]
$querySQL = "SELECT ID, TUT_TITLE, AUTHOR FROM $sTableName WHERE TUT_CAT=$inCatID AND APROVED = 1 ORDER BY ID ASC";[/code]
all i did was modify the $querySQL line to look like so. but for some reason that didnt make a diffrence at all!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.