Jump to content

How do I echo this variable the correct way?


Morris2

Recommended Posts

Hi.

 

Below is a working PHP script.

How do I echo the variable "artist" the correct way?

 

I've tryed everything I know, but cant get this to work ...

(in chronoforms in Joomla 1.7)

 

 

$chart2 = mysql_query("SELECT * FROM Combination where artist='$artistsearch' ORDER BY total DESC limit 5");

$num_rows = mysql_num_rows($chart2);     

while($row = mysql_fetch_assoc($chart2))

{echo $row['artist']." ... "

.$row['city']." ("

.$row['country'].") "

.$row['total']." USD<br>";}

 

Best regards Morris

 

Link to comment
Share on other sites

well firstly, you are echoing $row['artist'] correctly. I don't see any problems there. You could try substituting $row['artist'] for $artistsearch (since they should technically be the same value as that is what you are looking for in your SELECT query). However, if you want to use $row['artist'] you can try debugging the problem with the following steps:

 

print_r your $row array to see its contents (and verify they have the data  you expect them too)

check your database to make sure that the rows returned have the correct values in the artist column

echo or print your $artistsearch variable to verify it has the correct data.

 

A question: When you run this code, what happens? Is $row['artist'] seemingly blank (IE nothing is echoed where it should be echoed)? Is it the wrong artist?

Link to comment
Share on other sites

Hi.

 

Thanks for your very quick answer.

 

The values inside are all correct and echo'ing out the right way trough the script.

 

But I want to isolate the variable "artist" from the table, and echo it out in a separate line of code, something like this:

 

echo $row['artist'] (you said this was correct?)

 

But no matter how I try to change the code, it will not echo out.

 

What is the right notation in this case?

 

Best regards Morris

Link to comment
Share on other sites

row value is only available withing the array bracket.  Make variables for each item you wish to use outside this array.

	$chart2 = mysql_query("SELECT * FROM Combination where artist='$artistsearch' ORDER BY total DESC limit 5");
$num_rows = mysql_num_rows($chart2);     
while($row = mysql_fetch_assoc($chart2))
{
$city=$row['city'];
$country=$row['country'];
$total=$row['total'];
echo $row['artist']." ... "
.$row['city']." ("
.$row['country'].") "
.$row['total']." USD<br>";}
//You can then use the Variables outside the array
echo "City: $city<br />Country: $country<br />Total: $total";

Link to comment
Share on other sites

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.