SQL Query Not Displaying On Page

mimoser
mimoser used Ask the Experts™
on
For the life of me, trying various methods, I can't get the $Bux value to display on the page
The only thing that appears in the cell are ..  

Please help!!!
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
mysql_select_db($db) or die ("Unable to select database!"); 
$query = "select p.GiftID, p.GiftName, p.GiftURL
from voc2_users_gift up
inner join voc2_gift p on p.GiftID = up.GiftID
where up.id = 1";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
 
$query = "select Bux
from voc2_bux 
where id = 1";
 
if (mysql_num_rows($result) > 0)
?>
 Profile Example
 <br>
<table 	border="1" 
				width="69%" 
				bordercolorlight="#00FF00" 
				bordercolordark="#00FF00" 
				bgcolor="#000000" 
				id="table1" 
				height="164">
<tr><td>
  <table 	border="1" 
				width="100%" 
				bgcolor="#000000" 
				bordercolor="#00FF00" 
				id="table1" 
				height="222">
    <tr>
       <td width="481" height="33">
          <p align="center">
            <b><font color="#FFFFFF">Most Recent Gifts</font></b>
          </p>  
         </td>
        <td height="33" width="107">
          <p align="center">
            <b><font color="#FFFFFF"> 
          		<a href="gift.htm" style="font-style: italic"> 
          			<font color="#FFFFFF">Show All Gifts</font>
          		 </a>
          	 </font></b>
           </p>
          </td>  
        <td height="33"> 
          <p align="center">
          	<font color="#FFFFFF"><b><?=".$Bux."?></b></font>
          </p>
         </td> 
 			</tr> 
 		 <tr>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

$query2 = "select Bux
from voc2_bux
where id = 1";

$result2 = mysql_query($query2);

$bux = mysql_fetch_array($result2);

-
-
-

<font color="#FFFFFF"><b><?php echo "$Bux"; ?></b></font>
I can't say anything for sure because I don't know your table structure or exactly what you're trying to accomplish, so there may be some issues there that aren't apparent to me.  However, a few problems that jump right out at me:
  1. First and foremost, you never assign a value to $Bux (at least not in the code you've shown) so echoing $Bux will give you nothing.
  2. As for the two dots, that's the way you're echoing it... usually dots are used for concatenation of strings, but here you've got them within quotation marks and so they'll be echoed on either side of the value of $Bux.  I suggest you replace <?=".$Bux."?> with <?=$Bux?> or <?php echo $Bux; ?>
  3. You have two queries in your code above, but you only execute the first one.  That second one looks to be the one that might grab the value for $Bux, but you never actually execute it.
  4. Finally, I'm not sure if your code above would execute, but I recommend against splitting lines in the middle of a string (like you've done with your $query assignments).  Either keep it all on one line, or use concatenate statements like in the code box below.
$query = "select p.GiftID, p.GiftName, p.GiftURL from voc2_users_gift up inner join voc2_gift p on p.GiftID = up.GiftID where up.id = 1";
 
// or
 
$query = "select p.GiftID, p.GiftName, p.GiftURL ";
$query .= "from voc2_users_gift up ";
$query .= "inner join voc2_gift p on p.GiftID = up.GiftID ";
$query .= "where up.id = 1";

Open in new window

Author

Commented:
It still isn't showing the value of $Bux in that cell. It appears blank, but there is information in that table field, it's just rendering onto the page.

What else can I try?
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
mysql_select_db($db) or die ("Unable to select database!"); 
$query = "select p.GiftID, p.GiftName, p.GiftURL from voc2_users_gift up inner join voc2_gift p on p.GiftID = up.GiftID where up.id = 1";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
 
$query2 = "select Bux from voc2_bux where id = 1";
$result2 = mysql_query($query2);
$bux = mysql_fetch_array($result2);
 
 
if (mysql_num_rows($result) > 0)
?>
 Profile Example
 <br>
<table 	border="1" 
				width="69%" 
				bordercolorlight="#00FF00" 
				bordercolordark="#00FF00" 
				bgcolor="#000000" 
				id="table1" 
				height="164">
<tr><td>
  <table 	border="1" 
				width="100%" 
				bgcolor="#000000" 
				bordercolor="#00FF00" 
				id="table1" 
				height="222">
    <tr>
       <td width="481" height="33">
          <p align="center">
            <b><font color="#FFFFFF">Most Recent Gifts</font></b>
          </p>  
         </td>
        <td height="33" width="107">
          <p align="center">
            <b><font color="#FFFFFF"> 
          		<a href="gift.htm" style="font-style: italic"> 
          			<font color="#FFFFFF">Show All Gifts</font>
          		 </a>
          	 </font></b>
           </p>
          </td>  
        <td height="33"> 
          <p align="center">
          	<font color="#FFFFFF"><b><?=$Bux?></b></font>
 
          </p>
         </td> 
 			</tr> 
 		 <tr>

Open in new window

Author

Commented:
I found an corrected an error

$bux = mysql_fetch_array($result2);
to
$Bux = mysql_fetch_array($result2);

and now in the cell when I call for the $Bux data -
<font color="#FFFFFF"><b><?php echo "$Bux"; ?></b></font>

It's showing the word - Array

Please help!!

quick fix

change this portion of the code

$Bux = mysql_fetch_array($result2);

for this one


$Bux = mysql_result($result2,$i,'Bux');

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial