Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-18-2005, 09:31 AM Echo not displaying?
Skilled Talker

Posts: 59
Trades: 0
Code:
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","ODBC",""); 
	
//Select the database
mysql_select_db("test"); 

//Retrieve the ID which was submitted to the page
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM `clansnipe` WHERE `id` = '$id'");
{
//grab all the content
while($r=mysql_fetch_array($result))
  
   $clanname=$r["clanname"];
   $tag=$r["tag"];
   $gamesplayed=$r["gamesplayed"];
   $maingame=$r["maingame"];
   $established=$r["established"];
   $origin=$r["origin"];
   $url=$r["url"];
   
echo "$clanname <br> $tag <br> $gamesplayed <br> $maingame <br> $established <br> $origin <br> $url <br>"; 


echo $_GET['id'];
}
  	?>
For some reason, it'll only show one echo which is the first in line.
I've tried everything and it just won't show more than one!

Can anybody see why?
Thanks.
Btcc22 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-18-2005, 09:59 AM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
how many id's are there that are the same? ie how many results do you expect
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Old 07-18-2005, 10:16 AM
Skilled Talker

Posts: 59
Trades: 0
Well, what happens is:
There's a search page, you enter your search.
The results page shows all of the matches and partial matches.

Each result has an ID.
To view more information on the result, you click the link which is along the lines of:
file.php?id=5

This file I'm trying to fix then gets the number 5, looks it up in the database and shows all the information it has.
It works except it won't show more than one echo.

I'm trying to get it show a few bits of information, then, when it works I'll tell it to show all.

Thanks.
Btcc22 is offline
Reply With Quote
View Public Profile
 
Old 07-18-2005, 10:32 AM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
I was just trying to find out if there was more than one result in the associate array that is returned, so how many results should there be with the id as 5? hint "count your rows with mysql_num_rows($myQuery)"
//where query ="SELECT * FROM clansnipe WHERE id = '$id'";
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Old 07-18-2005, 10:46 AM
Skilled Talker

Posts: 59
Trades: 0
Well, the ID is unique to each entry.
Then, it should show 12 pieces of information when it's complete?
Btcc22 is offline
Reply With Quote
View Public Profile
 
Old 07-18-2005, 10:46 AM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
sorry it should read:
//where myQuery ="SELECT * FROM clansnipe WHERE id = '$id'";
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Old 07-18-2005, 10:56 AM
Skilled Talker

Posts: 59
Trades: 0
Sorry, where do you want me to put that?
It gives an error where ever I put it.
Btcc22 is offline
Reply With Quote
View Public Profile
 
Old 07-18-2005, 11:05 AM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
Well, the ID is unique to each entry.
Then, it should show 12 pieces of information when it's complete?

how can it show 12 if the id is unique? because you ask in your sql, show all records where the id field is equal to this id. (this id is the id that was passed from the link) or am I misunderstanding you? A quick pointer on your code mysql_query("SELECT * FROM `clansnipe` WHERE `id` = '$id'"); Table names and columns do not have a ‘ surrounding them in any sql as you will see from my post above, I have removed them.

Should it show 12 because there is 12 rows in your database? If yes then remove the WHERE clause from the query. hope this helps
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Old 07-18-2005, 11:14 AM
Skilled Talker

Posts: 59
Trades: 0
Let's say you search for "Apple".
There is a result for apple. The ID for "Apple" is "2".

When you click Apple, it goes to fruit.php?id=2

In the row, there are 12 items about the apple such as origin, cost etc

For now, it only shows Origin but I want it to show all of the information when I'm done.
That same code works for the result page (few changes of course to bring up the ID).

That's just an example, but it's the same scenario.

Thanks.
Btcc22 is offline
Reply With Quote
View Public Profile
 
Old 07-18-2005, 11:39 AM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
I see, you are not getting the full row!
Try this

$query = "SELECT * FROM clansnipe WHERE id = '$id'";

$querySet = mysql_query($query)
echo ‘<table>’;
while ($myArray = mysql_fetch_array($querySet, MYSQL_NUM))
{
$col0 = $ myArray [0];
$col1 = $ myArray [1];
$col2 = $ myArray [2];
echo ‘<tr><td>’. $col0 . ‘ ‘. $col1 .’ ‘. $col2 . ‘ </td> </tr>’;
}
echo ‘</table>’;

I haven’t tested it but should work. This uses a numbered array instead of an asso array (my personal preference). Hope this helps
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Old 07-18-2005, 11:45 AM
Skilled Talker

Posts: 59
Trades: 0
Code doesn't work at all.

Are you able to make any corrections such as echo " instead of ' please?

Sorry, new to all this.

Thanks very much!
Btcc22 is offline
Reply With Quote
View Public Profile
 
Old 07-18-2005, 11:57 AM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
No problem, could you give me the error message?
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Old 07-18-2005, 12:03 PM
Skilled Talker

Posts: 59
Trades: 0
Just a blank page. :S
Btcc22 is offline
Reply With Quote
View Public Profile
 
Old 07-18-2005, 12:06 PM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
err ok replace this line
$querySet = mysql_query($query)
with this:
$querySet = mysql_query($query) OR die("error with database $query".mysql_error());
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Old 07-18-2005, 12:12 PM
Skilled Talker

Posts: 59
Trades: 0
Changed your code accordingly, works!

Thanks very much for your time and help! Appreciated! ^_^
Btcc22 is offline
Reply With Quote
View Public Profile
 
Old 07-18-2005, 12:13 PM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
no probs lol took us a bit to get there!
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Reply     « Reply to Echo not displaying?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.22589 seconds with 12 queries