Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Wed Sep 28, 2005 4:06 pm
Take a look at my code below:
Code: Select all
<?php
$img = "specials";
$alt = "Specials";
include("layout.php");
include("connect.php");
?>
<table align="center" width="375" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><img src="img/middle2_top.gif"></td>
</tr>
<tr>
<td>
<table width="375" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="img/middle2_left.gif"><img src="img/middle2_left.gif"></td>
<td bgcolor="#FFFFFF" width="100%">
<table width="100%" border="0" cellpadding="5" cellspacing="1">
<tr>
<td align="center" colspan="2">
<font face="Verdana" size="2">
<h3>This Months Specials</h3>
Check back soon for next months specials!
</font>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<?php
$result = mysql_query("SELECT * FROM specials ORDER BY sortorder ASC");
while($row = mysql_fetch_array($result)) {
?>
<tr>
<td bgcolor="#E9E9E9" align="center">
<font face="Verdana" size="2"><b><?php echo $row["item"]; ?>:</b></font>
<br><br>
<a href="specials/<?php echo $row["file"]; ?>" target="_blank"><img src="thumbnail.php?dir=specials&file=<?php echo $row["file"]; ?>" alt="<?php echo $row["item"]; ?>" border="1"></a><br>
<font face="Verdana" size="1">(<a href="specials/<?php echo $row["file"]; ?>" target="_blank">Enlarge Photo</a>)</font>
<br><br>
<font face="Verdana" size="2" color="#FF0000"><b>Price:</b> $<?php echo $row["price"]; ?></font>
</td>
<td bgcolor="#E9E9E9" align="center">
<font face="Verdana" size="2"><b><?php echo $row["item"]; ?>:</b></font>
<br><br>
<a href="specials/<?php echo $row["file"]; ?>" target="_blank"><img src="thumbnail.php?dir=specials&file=<?php echo $row["file"]; ?>" alt="<?php echo $row["item"]; ?>" border="1"></a><br>
<font face="Verdana" size="1">(<a href="specials/<?php echo $row["file"]; ?>" target="_blank">Enlarge Photo</a>)</font>
<br><br>
<font face="Verdana" size="2" color="#FF0000"><b>Price:</b> $<?php echo $row["price"]; ?></font>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<?php
}
?>
</table>
</td>
<td background="img/middle2_right.gif"><img src="img/middle2_right.gif"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="img/middle2_bottom.gif"></td>
</tr>
</table>
<?php
footer();
?>
I want to make all of the records print out in that HTML format.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Wed Sep 28, 2005 4:40 pm
I'm confused what you are asking
Could you give us some more detail please?
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Wed Sep 28, 2005 4:51 pm
I want to print out records like this:
Code: Select all
<table>
<tr>
<td>row1</td>
<td>row2</td>
</tr>
<tr>
<td>row3</td>
<td>row4</td>
</tr>
</table>
But I have many rows, like 100!
I know I could use LIMIT to accomplish this im just not quite sure how.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Sep 28, 2005 7:28 pm
omega-systems
Forum Newbie
Posts: 14 Joined: Tue Sep 27, 2005 5:01 am
Contact:
Post
by omega-systems » Thu Sep 29, 2005 4:43 am
use this :
Code: Select all
//$page, $pagesize
//page - page number; pagesize - number of items at the page
$statement = "SELECT * FROM specials ORDER BY sortorder ASC";
$statement = $statement . " limit ".(($page-1)*$pagesize).", $pagesize";
$result = mysql_query($statement);
instead of your
Code: Select all
$result = mysql_query("SELECT * FROM specials ORDER BY sortorder ASC");
Regards,
Michael.
Project Manager
Omega Systems Ltd
Email:
info@omega-systems.biz
ICQ: 264962449
MSN:
omega-systems@hotmail.com
AIM: OmegaSys Ltd
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Thu Sep 29, 2005 2:11 pm
I want to have results from my database print out like this.
Every two rows into one <tr></tr>, then break into another <tr></tr> for the next two rows.
Like this:
Code: Select all
<table>
<tr>
<td>row1</td>
<td>row2</td>
</tr>
<tr>
<td>row3</td>
<td>row4</td>
</tr>
</table>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Sep 29, 2005 5:29 pm
did you read my link?
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Fri Sep 30, 2005 9:39 am
That link really doesent help me. Anyone else?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Sep 30, 2005 10:37 am
did you read this link from Useful Posts?
viewtopic.php?t=25105
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Tue Oct 04, 2005 6:07 pm
I don't want to use a class. It's more than what I need. There has got to be a way to accomplish what I'm trying to do without using a class. Please a code sample would be nice.
I want to have results from my database print out like this.
Every two rows into one <tr></tr>. Example:
Code: Select all
<tr>
<td>row1</td>
<td>row2</td>
</tr>
Then break into another <tr></tr> for the next two rows.
Final Print Out Like this:
Code: Select all
<table>
<tr>
<td>row1</td>
<td>row2</td>
</tr>
<tr>
<td>row3</td>
<td>row4</td>
</tr>
<tr>
<td>etc.</td>
<td>etc.</td>
</tr>
</table>
mickd
Forum Contributor
Posts: 397 Joined: Tue Jun 21, 2005 9:05 am
Location: Australia
Post
by mickd » Tue Oct 04, 2005 6:34 pm
something like this should do it (prolly needs tweaking)
Code: Select all
echo '<table>';
$rownum = 1;
while($row = mysql_fetch_assoc($result)) {
if($rownum == '1') {
echo '<tr>
<td>' . $row['name'] . '
</td>';
$rownum++;
} elseif($rownum = 2) {
echo '
<td>' . $row['name'] . '
</td>
</tr>';
$rownum = 1;
}
}
if((mysql_num_rows($result) % 2) == 1) {
echo '</tr>';
}
echo '</table>';
Last edited by
mickd on Tue Oct 04, 2005 7:26 pm, edited 2 times in total.
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Tue Oct 04, 2005 6:52 pm
The code above is what I am trying to do, but it doesent work fully. I get an error on the mysql_fetch_assoc line. Help please?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Tue Oct 04, 2005 7:21 pm
before that line did you add a connection to your database along with a query?
Code: Select all
$connection = mysql_connect('localhost','user','pass') or die('Connection Failed');
$result = mysql_query('SELECT * FROM `table`') or die(mysql_error());
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Oct 04, 2005 7:38 pm
class? what class? the links I posted have nothing to do with a class..