View Full Version : MySQL database stuff not showing up in php!


TanisLinkEragon
08-21-2006, 02:44 PM
whenever i try to call a value from my MySQL database, and put it into a variable, when i echo the variable, nothing shows up!!

heres the code:
<?php
$con = mysql_connect("MyServer","MyDBusername","myDBpass");
if (!$con)
{
die('Could not connect: changes WERENT made. Please contact Tanis' . mysql_error());
}
mysql_select_db("dbo174648027", $con);
$hcplasto=mysql_query("SELECT HC_Plasto FROM HC_Rares");
$mocha=mysql_query("SELECT Mocha FROM HC_Rares");
$dice=mysql_query("SELECT Dice_Master FROM HC_Rares");
$tubmaster=mysql_query("SELECT Tub_Master FROM HC_Rares");
$impt=mysql_query("SELECT Imp_Tele FROM HC_Rares");
$throne=mysql_query("SELECT Throne FROM HC_Rares");
$oil=mysql_query("SELECT Oil_Lamp FROM HC_Rares");
$nordic=mysql_query("SELECT Nordic FROM HC_Rares");
$majestic=mysql_query("SELECT Majestic_Chair FROM HC_Rares");
$study=mysql_query("SELECT Study_Desk FROM HC_Rares");

echo $study;
echo $hcplasto;
echo $dice;
?>

EhraniNavy
08-21-2006, 03:10 PM
Try this:


<?php
$con = mysql_connect("MyServer","MyDBusername","myDBpass" );
if (!$con)
{
die('Could not connect: changes WERENT made. Please contact Tanis' . mysql_error());
}
mysql_select_db("dbo174648027", $con);
$query = "SELECT * FROM HC_Rares";
$result = mysql_query($query)
//Now you have to fetch the array
if ($result) {
while ($row = mysql_fetch_array($result)) {
$myvariable = $row['myvariable'];
}
}
echo $myvariable;
mysql_close();
?>

As to what you are trying to do, I don't see how you are trying to have one variable contain all the information from a column.

TanisLinkEragon
08-21-2006, 03:49 PM
I dont think that would work, because i need seperate variables for all the info, each thing in the DB has to be stored into a seperate variable, so i can echo them all seperately.

EhraniNavy
08-21-2006, 04:09 PM
Well the reason that you couldn't display anything was because you need to use mysql_fetch_array($result) to grab the results of your query. For each row of the table, you can get the value for each column.

Is each of what you are trying to SELECT in your first post a row or a field? Right now, the SELECT Throne FROM HC_Rares is trying to grab a table that contains all the information from the row Throne.

Phillip
08-21-2006, 04:31 PM
This should work:


<?php
$con = mysql_connect("MyServer","MyDBusername","myDBpass" );
if (!$con)
{
die('Could not connect: changes WERENT made. Please contact Tanis' . mysql_error());
}
mysql_select_db("dbo174648027", $con);
$query = "SELECT * FROM HC_Rares";
$result = mysql_query($query);
//Now you have to fetch the array

if (@mysql_num_rows($result) == 1) {
while ($row = mysql_fetch_array($result)) {
echo '<p>The hc sofa is valued at:' .$row['hc_sofa']. '</p>';
echo '<p>The hc plasto chair was valued at:' .$row['plasto_chair']. '</p>';

}
}
mysql_close();
?>


:) Sorry for double post, the script had some errors :blush:

TanisLinkEragon
08-21-2006, 05:24 PM
Lol, yes it does rock :D


anyways, thanks a ton!

Phillip
08-21-2006, 05:32 PM
Did it work? And which hotel do you play :lolo:

TanisLinkEragon
08-21-2006, 06:21 PM
Yes, it did work.
at least the part that you gave me :S

now i get Parse error: unnexpected $ on line 146 >.>

143- mysql_close($con);
144- ?>
145- </body>
146- </html>


I fail to see any $.....

Hotel-USA, habbo name- TanisLinkEragon ;)

Douglas
08-21-2006, 06:45 PM
Give the entire file with that content in it

TanisLinkEragon
08-21-2006, 07:36 PM
:S

its 644 characters too long to post...

Heres the code (http://www.habbground.com/source.html)
(sorry about the horrible font :blush: )

Phillip
08-22-2006, 12:18 AM
try changing mysql_close($con);

to: mysql_close();

Douglas
08-22-2006, 12:29 AM
I didn't mean that page lol, I meant maincontent.php the one that is included :) And Phill that really doesn't make a difference.

TanisLinkEragon
09-05-2006, 08:42 PM
<div id=top style="position:absolute;right:0px;top:0px;z-index:15;width:1004px;height:228px; background-color:black;">
<img src="hgtop.JPG"></div>
<style type="text/CSS">
#container {
width:100%;
text-align:center;
margin-bottom:10px;
border-right:none;
border-left:none;
clear:both;
}
#container div {
display:inline
}
</style>
<script type="text/javascript">
var Moffset = 50;
var floatOffset=0;
function resetPos()
{
str=document.documentElement.scrollTop+Moffset;
document.getElementById('thediv').style.top=str+'p x';
document.getElementById('floater').style.top=(floa tOffset+document.documentElement.scrollTop)+'px';
}
window.onscroll=resetPos;
</script>
</head>

<body background="hg1-1">
<body>
<script type='text/javascript'>

//HV Menu v5.411- by Ger Versluis (http://www.burmees.nl/)
//Submitted to Dynamic Drive (http://www.dynamicdrive.com)
//Visit http://www.dynamicdrive.com for this script and more

function Go(){return}

</script>
<script type='text/javascript' src='exmplmenu_var.js'></script>
<script type='text/javascript' src='menu_com.js'></script>
<noscript>Your browser does not support script</noscript>

<div id="thediv" style="position:absolute;left:0px;top:50px;z-index:20;width:100px; background-color:black;">
<img src="hg2.jpg"> </div>
<div id="floater" style="position:absolute;right:0px;top:40px;z-index:15;width:90px; background-color:black;">
<img src="hg3.jpg"></div>





<center>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>

there ya go!

sorry bout the wait, ive been having some issues with my computer :)

TanisLinkEragon
09-17-2006, 11:14 PM
Sorry for the double post, that was the maincontent.php source.