Mysql display results
Ok I am stumped. I am inserting the data fine into the table and database so i know its not the config.php nor opendb.php. I used a code like this before and it work, i've only altered the $sql, the td's, and the $rows[]. Table name is hotspots (all lower case) all of the column names are lower case also. Column names are id, topic, comment, username, timestamp. Here's the code.
$sql="SELECT * FROM hotspots ORDER BY id DESC";
$result=mysql_query($sql);
$color="1";
echo '<table width="472px" border="0" align="center" cellpadding="2" cellspacing="0" style="border:1px solid #0000ff;">';
while($rows=mysql_fetch_array($result)){
if($color==1){
echo "<tr bgcolor='#6698FF' >
<td style='border-top:1px solid #0000ff; color:#000000;font-weight: bold;'>".$rows['username']."</td><td style='border-top:1px solid #0000ff; text-align: right;color:#000000;font-weight: bold;'>".$rows['timestamp']."</td></tr>
<tr bgcolor='#6698FF' style='border-bottom:1px solid #0000ff;color:#000000;font-weight: bold;'><td style=''>".$rows['topic']."</td><td style='text-align: right;color:#000000;font-weight: bold;'>".$rows['timestamp']."</td>
</tr><tr bgcolor='#6698FF'><td colspan='2' bgcolor='#6698FF'></td></tr><tr bgcolor='#6698FF'><td colspan='2' bgcolor='#6698FF'></td></tr><tr bgcolor='#6698FF'; style='border-bottom:1px solid #0000ff;' color:#000000;font-weight: bold;'><td colspan='2' style='color:#ffffff;font-weight: bold;font-size:13px;''>".$rows['comment']."</td>
</tr><tr bgcolor='#6698FF'><td style='border-bottom:1px solid #0000ff;' colspan='2' bgcolor='#6698FF'></td></tr>";
$color="2";
} else {
echo "<tr bgcolor='#AFDCEC'>
<td style='border-top:1px solid #0000ff;color:#0000ff;font-weight: bold;'>".$rows['username']."</td><td style='border-top:1px solid #0000ff; text-align: right;color:#0000ff;font-weight: bold;'>".$rows['timestamp']."</td></tr>
<tr bgcolor='#AFDCEC' style='border-bottom:1px solid #0000ff;color:#0000ff;font-weight: bold;'><td style=''>".$rows['topic']."</td><td style='text-align: right;color:#0000ff;font-weight: bold;'>".$rows['timestamp']."</td>
</tr><tr bgcolor='#AFDCEC'><td colspan='2' bgcolor='#AFDCEC'></td></tr><tr bgcolor='#AFDCEC'><td colspan='2' bgcolor='#AFDCEC'></td></tr><tr bgcolor='#AFDCEC' style='border-bottom:1px solid #0000ff;color:#0000ff;font-weight: bold;'><td colspan='2' style='color:#0000ff;font-weight: bold;font-size:13px;'>".$rows['comment']."</td>
</tr><tr bgcolor='#AFDCEC'><td style='border-bottom:1px solid #0000ff;' colspan='2' bgcolor='#AFDCEC'></td></tr>";
$color="1";
}
}
echo '</table>';
RazorRamon
Junior Poster in Training
74 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
This is the HTML code that calls the code above. I titled the code above viewcomments.php. I haven't uploaded this website, right now I am only testing it on wamp. There are no errors it just doesn't display what is in the table. I currently only have one entry in the table that I inserted using this HTML code and inserttopic.php that the form is directed to use. inserttable.php also uses config2.php and opendb.php to connect to the database which is why I know that is not the issue. Sorry Zagga I know the code is sloppy.
<html>
<body>
<DIV >
<table width="480" BACKGROUND="images/commentback.jpg">
<tr>
<td>
<form method="post" action="inserttopic.php">
<span class="whitetitle">Topic: <input name="topic" type="text" STYLE="background: white; border: 1px #000000 solid;"><br >
Username:<input name="username" type="text" STYLE="background: white; border: 1px #000000 solid;"><br >
Comment:<br >
<textarea name="comment" rows="4" cols="55" STYLE="background: white; border: 1px #000000 solid;">250 char. max</textarea><br >
<input type="submit" value="send"></span>
</form>
</td>
</tr>
</table>
</div>
<?php
include 'config2.php';
include 'opendb.php';
include 'viewcomments.php';
include 'closedb.php';
?>
</body>
</html>
RazorRamon
Junior Poster in Training
74 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
I tried
print_r($rows);
no luck. I have a question though, do i need to set $rows to something before using it?
RazorRamon
Junior Poster in Training
74 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
$result= mysql_query("SELECT * FROM `hotspots` ORDER BY `id` DESC")or die (mysql_error());
$color="1";
echo '<table width="472px" border="0" align="center" cellpadding="2" cellspacing="0" style="border:1px solid #0000ff;">';
while($rows=mysql_fetch_array($result)){
if($color==1){
?>
<tr bgcolor='#6698FF' >
<td style='border-top:1px solid #0000ff; color:#000000;font-weight: bold;'><? echo $rows[username]; ?></td><td style='border-top:1px solid #0000ff; text-align: right;color:#000000;font-weight: bold;'><? echo $rows[timestamp]; ?></td></tr>
<tr bgcolor='#6698FF' style='border-bottom:1px solid #0000ff;color:#000000;font-weight: bold;'><td style=''><? echo $rows[topic]; ?></td><td style='text-align: right;color:#000000;font-weight: bold;'><? echo $rows[timestamp]; ?></td>
</tr><tr bgcolor='#6698FF'><td colspan='2' bgcolor='#6698FF'></td></tr><tr bgcolor='#6698FF'><td colspan='2' bgcolor='#6698FF'></td></tr><tr bgcolor='#6698FF'; style='border-bottom:1px solid #0000ff;' color:#000000;font-weight: bold;'><td colspan='2' style='color:#ffffff;font-weight: bold;font-size:13px;''><? echo $rows[comment]; ?></td>
</tr><tr bgcolor='#6698FF'><td style='border-bottom:1px solid #0000ff;' colspan='2' bgcolor='#6698FF'></td></tr>
<?
$color="2";
}else{ ?>
<tr bgcolor='#AFDCEC'>
<td style='border-top:1px solid #0000ff;color:#0000ff;font-weight: bold;'><? echo $rows[username]; ?></td><td style='border-top:1px solid #0000ff; text-align: right;color:#0000ff;font-weight: bold;'><? echo $rows[timestamp]; ?></td></tr>
<tr bgcolor='#AFDCEC' style='border-bottom:1px solid #0000ff;color:#0000ff;font-weight: bold;'><td style=''><? echo $rows[topic]; ?></td><td style='text-align: right;color:#0000ff;font-weight: bold;'><? echo $rows[timestamp]; ?></td>
</tr><tr bgcolor='#AFDCEC'><td colspan='2' bgcolor='#AFDCEC'></td></tr><tr bgcolor='#AFDCEC'><td colspan='2' bgcolor='#AFDCEC'></td></tr><tr bgcolor='#AFDCEC' style='border-bottom:1px solid #0000ff;color:#0000ff;font-weight: bold;'><td colspan='2' style='color:#0000ff;font-weight: bold;font-size:13px;'><? echo $rows[comment]; ?></td>
</tr><tr bgcolor='#AFDCEC'><td style='border-bottom:1px solid #0000ff;' colspan='2' bgcolor='#AFDCEC'></td></tr>
<?
$color="1";
}
}
echo'</table>';
Try that - I didn't see anything immediately wrong with it though.
public-image
Junior Poster in Training
76 posts since Oct 2010
Reputation Points: 10
Solved Threads: 11
Great IIM!!! thanks it worked!!! thanks for all the help everybody..
RazorRamon
Junior Poster in Training
74 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0