...

View Full Version : Problem didplaying MySQL data



Zenzie
10-24-2004, 05:27 PM
I am trying to make a script that will disply a users points (bits), but it always shows up as 1 when the number in the database is something else. Here is my code:


<?php
include("config.php");
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db(sparky_data)
or die ("Could not select database because ".mysql_error());
$cookie = $HTTP_COOKIE_VARS["starbits_username"];
$qry = mysql_query("SELECT bits FROM users WHERE username = '$cookie'") or die ("Could not get data because " . mysql_error());
$get_info = print_r($qry);
echo "<br>Bits: <a href='bits.php'>$get_info</a>";
?>

KeZZeR
10-24-2004, 05:36 PM
echo "<br>Bits: <a href='bits.php'>$get_info</a>";

There's where your problem is at. It's better to do it like this:


echo '<br>Bits: <a href="bits.php">' . $get_info . '</a>';

Now try that :)

EDIT: That's if you are trying to get the output from the $get_info variable to display between the anchor tags i hope. Otherwise i'm making myself look stupid ;)

As5a5sIn5
10-24-2004, 05:37 PM
trying to echo the query? tsk tsk...lol
you have to add this ...


<?php
include("config.php");
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db(sparky_data)
or die ("Could not select database because ".mysql_error());
$cookie = $HTTP_COOKIE_VARS["starbits_username"];
$qry = mysql_query("SELECT bits FROM users WHERE username = '$cookie'") or die ("Could not get data because " . mysql_error());
while($row = mysql_fetch_assoc($qry)){
$get_info = $row[bits];
}
echo "<br>Bits: <a href='bits.php'>$get_info</a>";
?>
I'm pretty sure that will work...the $row[bits] part mite be wrong cuz idk what row you want to grab...good luck

Zenzie
10-24-2004, 06:05 PM
Thanks! Let me see if this will work...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum