Jump to content


Photo

**SOLVED** Querying database


  • Please log in to reply
3 replies to this topic

#1 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 01 June 2006 - 03:18 AM

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.

<?

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

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

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!!!

<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>

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

Please help!

-Thanks

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 June 2006 - 06:36 AM

[!--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

$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);

If it is messed up, you will get the error message telling you why and the query string will be echoed'
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 01 June 2006 - 02:58 PM

ok, Thanks for that. now I want them in ASC order.
so that the last row of the database displays first.
$querySQL = "SELECT ID, TUT_TITLE, AUTHOR FROM $sTableName WHERE TUT_CAT=$inCatID AND APROVED = 1 ORDER BY ID ASC";
all i did was modify the $querySQL line to look like so. but for some reason that didnt make a diffrence at all!



#4 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 01 June 2006 - 05:04 PM

Nevermind I figured everything out!

Thanks for all your help! :)







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users