Problem! Need solution.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
omanush
Forum Newbie
Posts: 9
Joined: Thu Jul 24, 2003 8:58 pm
Location: Montreal, QC
Contact:

Problem! Need solution.

Post by omanush »

I’m totally new to programming; trying to learn PHP by editing/creating small scripts. But this one really got me. Here is the template I’m using http://www.dollar5.com/test/datafeed/datafeed.php. All I want to do is display 30 or more records per page. It’s not a big deal for you guys but for me it’s kind of rocket science. Please help me out with this problem.

Code: Select all

<?php
$link = mysql_connect('localhost', 'user', 'pass');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}

mysql_select_db("dollar5_datafeed", $link)
or die("Couldn't open $db: ".mysql_error());
if(!$rowstart) $rowstart=0;
$query = "SELECT `name`, `keyword`, `desc`, `url`, `imgsm`, `imglr`, `price`, `cat1`, `cat2` FROM test limit $rowstart,1";

$result = mysql_query($query)
or die("SELECT Error: ".mysql_error());
if(!$result) error_message(sql_error());

$query_data = mysql_fetch_array($result);
$name = $query_data["name"];
$keyword = $query_data["keyword"];
$desc = $query_data["desc"];
$url = $query_data["url"];
$imgsm = $query_data["imgsm"];
$imglr = $query_data["imglr"];
$price = $query_data["price"];
$cat1 = $query_data["cat1"];
$cat2 = $query_data["cat2"];

// Display CSS Table

$display = "<table align="center" cellspacing="0" class="table">
        <tr class="td-top"> 
          <td colspan="2" class="name">$name</td>
        </tr>
        <tr class="tr-bottom"> 
          <td align="center" class="td-left"><a href="$imglr" target="_blank"><img src="$imgsm"class="smallimg"></td>
          <td class="td-right"><p class="desc">$desc
            <p class="price">Special Sale Price: <span class="amount">$ $price</span></p>
            <a href="$url" target="_blank"><img src="details_normal.gif" alt="$name" width="100" height="22" border="0" class="details" hsrc="details_over.gif"></a> 
          </td>
        </tr>
      </table><br>";
	  
	  
	  
	  
mysql_close($link); 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<script language="JavaScript" type="text/JavaScript">
function init() {
if (!document.getElementById) return
var imgOriginSrc;
var imgTemp = new Array();
var imgarr = document.getElementsByTagName('img');
for (var i = 0; i < imgarr.length; i++) {
if (imgarr[i].getAttribute('hsrc')) {
imgTemp[i] = new Image();
imgTemp[i].src = imgarr[i].getAttribute('hsrc');
imgarr[i].onmouseover = function() {
imgOriginSrc = this.getAttribute('src');
this.setAttribute('src',this.getAttribute('hsrc'))
}
imgarr[i].onmouseout = function() {
this.setAttribute('src',imgOriginSrc)
}
}
}
}
onload=init;
</script>
<style type="text/css">
<!--
@import url("TEST.css");
-->
</style>

<body>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" class="tabletotalresult">
  <tr>
    <td> Datafeed Test</td>
  </tr>
</table><br>

<? echo "$display";?>

<br>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td align="right"><table width="220" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td>

		  <a href="<? $php_self ?>?rowstart=<? echo $rowstart-1;?>"><img src="prev-norm.gif" width="100" height="22" border="0" hsrc="prev-over.gif"></a></td>
          <td align="right"><a href="<? $php_self?>?rowstart=<?echo $rowstart+1 ;?>"><img src="next-norm.gif" width="100" height="22" border="0"  hsrc="next-over.gif"></a></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

What's the problem?
omanush
Forum Newbie
Posts: 9
Joined: Thu Jul 24, 2003 8:58 pm
Location: Montreal, QC
Contact:

Post by omanush »

I’m trying to display 30 or more records from the database on This Page without creating separate html tables for each record.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

here we go

Code: Select all

// your output is defined here
// I HAVE CHANGED IT
$display = "<tr class="td-top"> 
          <td colspan="2" class="name">$name</td> 
        </tr> 
        <tr class="tr-bottom"> 
          <td align="center" class="td-left"><a href="$imglr" target="_blank"><img src="$imgsm"class="smallimg"></td> 
          <td class="td-right"><p class="desc">$desc 
            <p class="price">Special Sale Price: <span class="amount">$ $price</span></p> 
            <a href="$url" target="_blank"><img src="details_normal.gif" alt="$name" width="100" height="22" border="0" class="details" hsrc="details_over.gif"></a> 
          </td> 
        </tr> ";
//new echo statement
// you should loop the follow lines
// removing the $display variable and looping normally is
// also recommended
print "<table width="100%">";
// start a loop here
print "$display";
// end the loop here
print "</table>";
this also makes sure the table is "wrapped up"
omanush
Forum Newbie
Posts: 9
Joined: Thu Jul 24, 2003 8:58 pm
Location: Montreal, QC
Contact:

Post by omanush »

Thank you so much for quick reply. Actually I’m getting confused. Don’t know how to explain but let me give a try.

I’ve been searching on google.com and find out about mysql_fetch_row. Here is an example of what I was trying to do:

Code: Select all

<?php
$link = mysql_connect('xxxxx.com', ‘user’, 'pass');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}

mysql_select_db("dollar5_datafeed", $link)
or die("Couldn't open $db: ".mysql_error());

$query = "SELECT `name`, `keyword`, `desc`, `url`, `imgsm`, `imglr`, `price`, `cat1`, `cat2` FROM test";

$result = mysql_query($query)
or die("SELECT Error: ".mysql_error());
if(!$result) error_message(sql_error());

$query_data = mysql_fetch_array($result);
$name = $query_data["name"];
$keyword = $query_data["keyword"];
$desc = $query_data["desc"];
$url = $query_data["url"];
$imgsm = $query_data["imgsm"];
$imglr = $query_data["imglr"];
$price = $query_data["price"];
$cat1 = $query_data["cat1"];
$cat2 = $query_data["cat2"];

$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){ 
print "<tr>\n";
foreach ($get_info as $field) 
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";

mysql_close($link); 
?>
The Result is: http://www.dollar5.com/test/datafeed/nolimit.php

----
But I want to use my own table structure to display the data; for example 500 records will be displayed in 500 separate tables or 100 records will be displayed in 100 separate tables. It’s like Repeat Region in Dreamweaver.

Almost 22 hours of restless trying but still have no clue how to do this. Excited but also upset …Please give me some idea…

Merci…
Post Reply