StudioTime
StudioTime

Reputation: 23979

Select twice from one query MySQL - PHP

I have the following select statement:

$wishes = mysql_query("select count(*) as how_many_total, PRprodinfo_id, main_category from user_lists where user_id = '$user_cookie' order by main_category;",$db);

Now, halfway down my page i need to extract the how_many_total value, then, if that is above 0 i need to run a fetch array on this query to print the results out

Do i need to use two queries to do this? e.g. one to count then if > 0 another select? when I try to fetch array twice or even combo of fetch row then fetch array i get errors

many thanks

darren

Upvotes: 0

Views: 551

Answers (1)

Flo
Flo

Reputation: 1671

you can let the complete count(*) out of your query and just use

if (mysql_num_rows($wishes) > 0)

to get the number of results and then do whatever you want like fetching the rows

Upvotes: 2

Related Questions