Jump to content

Recommended Posts

First my hosting information, and program versions:

 

hostinginfo.jpg

 

- I have this table (mysql) with 3 columns:

 

ID Country     Target

1 US             North America

2 ES             EUROPE

3 ES             West Europe

4 SA             Africa

5 US             American Continent

 

If I do this:

 

$resulttargetcr = mysql_query("SELECT Target FROM table WHERE Country='US');
$rowtargetcr = mysql_fetch_row ($resulttargetcr);

 

I only get first result.

1) North America

 

 

The problem is that I want to get all results:

1) North America

2) American Continent

 

- How can I get all results?

 

- I then want to use this results (all of them) on another query:

$rowtargetcreach = "'" . implode("', '", $rowtargetcr) . "'";
$query2 = mysql_query("SELECT Target2 FROM table2 WHERE trgcountry='$rowtargetcreach');

 

But It doesnt works either.

 

Please help,

thank you.

 

 

To display all the info you need a while loop like this:

 

$resulttargetcr = mysql_query("SELECT Target FROM table WHERE Country='US'") or die(mysql_error());
while($rowtargetcr = mysql_fetch_row ($resulttargetcr)) {
   echo $rowtargetcr['ID'] . " - " .  $rowtargetcr['Country'] . " - " . $rowtargetcr['Target'] . "
";
}

 

Then just do your other query inside this while loop.

 

thank you for your answer.

 

but I need the results out of the while loop.

Its there a way to get all the results outside the while loop?

 

I tried your code, and then this:

$rowtargetcreach = "'" . implode("', '", $rowtargetcr) . "'";

 

But it doesnt work

 

Its there a way to get all the results outside the while loop?

Feel free to push onto an array if you so choose.

 

Thank you for your answer.

 

Can you give me some code example?

I have tested a few methods but I do not know how to make it work.

If I do a while loop, and foreach, I can not get the results outside the loop.

If I do not make a while loop, I can not get all the results...

thanks for your time.

$resultarray = arry();
$resulttargetcr = mysql_query("SELECT Target FROM table WHERE Country='US'") or die(mysql_error());
while($rowtargetcr = mysql_fetch_row ($resulttargetcr)) {
   $resultarray[] = $rowtargetcr['Target'];
}

 

This will give you an array called $resultarray which contains all your results.

 

I then want to use this results (all of them) on another query:

 

I would highly recommend taking a look at the tutorial on www.phpfreaks.com in regard to joins and unions before executing multiple queries using one result from another. You can usually get what you need done in one query.

$resultarray = arry();
$resulttargetcr = mysql_query("SELECT Target FROM table WHERE Country='US'") or die(mysql_error());
while($rowtargetcr = mysql_fetch_row ($resulttargetcr)) {
   $resultarray[] = $rowtargetcr['Target'];
}

 

This will give you an array called $resultarray which contains all your results.

 

I then want to use this results (all of them) on another query:

 

I would highly recommend taking a look at the tutorial on www.phpfreaks.com in regard to joins and unions before executing multiple queries using one result from another. You can usually get what you need done in one query.

 

THANK YOU very much, it works great.

And I will take a look at the tutorial on www.phpfreaks.com in regard to joins and unions....

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.