Help with selecting stuff and placing them into $ad_rowset

PHP coding talk.

Moderator: Moderators

Help with selecting stuff and placing them into $ad_rowset

Postby webnoobie on Thu Mar 08, 2007 11:13 am

Hello,

I am working on a script that will select specific ads from a specific table from the database. Here is my code:

Code: Select all
$sql = "SELECT *
   FROM " . ADS_TABLE . "
   WHERE ad_cat_id = " . $cat_id . "
      AND ad_status = 1
      AND ad_sold = 0
   ORDER BY ad_id DESC";
if( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain Ad information for this category', '', __LINE__, __FILE__, $sql);
}

$total_ads = 0;
while( $row = $db->sql_fetchrow($result) )
{
   $ad_rowset = $row;
   $total_ads++;
}
$db->sql_freeresult($result);

if( $total_ads )
{
   for( $i = 0; $i < $total_ads; $i++ )
   {
      $ad_id = $ad_rowset[$i]['ad_id'];
      $ad_name = $ad_rowset[$i]['ad_name'];
      
      echo $ad_rowset[$i]['ad_name'];      
      echo $ad_name;
   }
}


But when I try to echo $ad_name that is within the for loop, It does not echo. When I go and echo $ad_rowset['ad_name']; after the while statement, it is successful. What would cause the code not to echo the $ad_rowset[$i]['ad_name']; that is within the for loop?

Thanks for the help in Advance! It is most appreciated! :D
Best Regards:
webnoobie
webnoobie
Registered User
Registered User
 
Posts: 366
Joined: Wed Jun 08, 2005 10:38 pm
Location: My Computer

Postby PostBot on Thu Mar 08, 2007 11:15 am

change line 15 to:[code start="15"] $ad_rowset[highlight][][/highlight] = $row;[/code]
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby webnoobie on Thu Mar 08, 2007 11:22 am

Thank-you very much CyberAlien ! :D It is most appreciated.

Also, I love your new sites that you have. the ST Software one and the Tutorial One :D If you dont mind me asking, what does the ST stand for?
Best Regards:
webnoobie
webnoobie
Registered User
Registered User
 
Posts: 366
Joined: Wed Jun 08, 2005 10:38 pm
Location: My Computer

Postby PostBot on Thu Mar 08, 2007 11:26 am

Thanks :D ST = Slava (short version of "Vjacheslav") Trushkin.

More websites are coming soon :wink:
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby webnoobie on Thu Mar 08, 2007 11:27 am

:D

I can't wait! Your websites and software is very professional and I love em :)

Thanks for all the help CA :D
Best Regards:
webnoobie
webnoobie
Registered User
Registered User
 
Posts: 366
Joined: Wed Jun 08, 2005 10:38 pm
Location: My Computer


Return to PHP Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron