Jump to content


Photo

Solved


  • Please log in to reply
25 replies to this topic

#21 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 11:35 AM

OK, try changing to this:

<?php
$y = <<<HTML
<table align="center" border="0" cellpadding="0" cellspacing="0" width="145">
  <tr>
    <td width="16"><img src="about_files/top_lef.gif" alt="a" width="16" height="16">
    </td>
    <td background="about_files/top_mid.gif" height="16">
      <img src="about_files/top_mid.gif" alt="a">
    </td>
    <td width="16">
      <img src="about_files/top_rig.gif" alt="a" width="16" height="16">
    </td>
  </tr>
  <tr>
    <td background="about_files/cen_lef.gif" width="16">
      <img src="about_files/cen_lef.gif" alt="a">
    </td>
    <td align="left" bgcolor="#ffffff" valign="middle">
      <div align="center">
        <img src="{$cat}/{$i}.jpg" width="114" height="86" border="1">
      </div>
    </td>

    <td background="about_files/cen_rig.gif" width="16">
      <img src="about_files/cen_rig.gif" alt="a">
    </td>
  </tr>
  <tr>
    <td height="16" width="16">
      <img src="about_files/bot_lef.gif" alt="a" width="16" height="16">
    </td>
    <td background="about_files/bot_mid.gif" height="16">
      <img src="about_files/bot_mid.gif" alt="a">
    </td>
    <td height="16" width="16">
      <img src="about_files/bot_rig.gif" alt="a" width="16" height="16">
    </td>
  </tr>
</table>
HTML;

echo "$y";
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#22 mendoz

mendoz
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts

Posted 28 September 2006 - 11:54 AM

Seems to work good.

Is there a var in your script whose value is the row number?

I tought it was $i but it wasn't.
<img src="{$cat}/thumbs/{$i}.jpg" width="114" height="86" border="1">

Then I tried using $r but it just gave 0 and 1, i know why.

Maybe I need to add a while function?

#23 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 12:02 PM

There was, but I didn't think you'd be using it... It's in the code, but it's commented out:

<?php
$y = mysql_result($result, $x, 0); // Commented out so I could show your example
?>

What this does is get the data for a particular cell.  Check the manual for the mysql_result function.  I've given it three parameters.  The first is the result set to use, the second is the database row number, as you can see, I've used $x as that's my table row number and finally a field offset.  My data was in the first column, so I had no need to offset, hence the 0.

This maybe a little confusing, but you should be OK.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#24 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 01:03 PM

Something else you should probably change, underneath this code:

<?php
mysql_connect( "localhost", "user", "pass" ); // Use correct stuff there
mysql_select_db( "database" ); // Use Database Name
?>

Replace this:

$cat=$_GET['cat'];

With this:

if (isset($_GET['cat'])) $cat = $_GET['page']; else $cat = "star";

Is this line, all it does is provide a default category incase someone attempts to get to test.php on its own without specifiying one.

Let me know if you're still having problems.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#25 mendoz

mendoz
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts

Posted 28 September 2006 - 07:40 PM

Well, most of the code seems to work right

The only thing missing is that the first img is 5.jpg and not 1.jpg

http://10bayad.com/test.php?cat=star


<?php

mysql_connect( "XX", "XX", "XX" ); // Use correct stuff there
mysql_select_db( "10bayad" ); // Use Database Name
$cat=$_GET['cat'];

// Select total results for pagination
$result = mysql_query("SELECT count(id) FROM $cat");
$num_records = mysql_result($result,0,0);

// Set maximum number of rows and columns
$max_num_rows = 2;
$max_num_columns = 3;
$per_page = $max_num_columns * $max_num_rows;

// Work out how many pages there are
$total_pages = ceil($num_records / $per_page);

// Get the current page number
if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1;

// Work out the limit offset
$start = ($page - 1) * $per_page;

// Select the results we want including limit and offset
$result = mysql_query("SELECT id FROM $cat ORDER BY id LIMIT $start, $per_page");
$num_columns = ceil(mysql_num_rows($result)/$max_num_rows);
$num_rows = ceil(mysql_num_rows($result)/$num_columns);

// Echo the results
echo "<table bgcolor=\"#D5D5D5\" border=\"2\">\n";
for ($r = 0; $r < $max_num_rows; $r++){
	echo "<tr>\n";
	for ($c = 0; $c < $max_num_columns; $c++){ // 1
		$x = $r * $max_num_columns + $c;
		if ($x < mysql_num_rows($result)){
//                   $y = mysql_result($result, $x, 0); // Commented out so I could show your example
                     $num = mysql_result($result, $x, 0);

                   $y = <<<HTML
<table align="center" border="0" cellpadding="0" cellspacing="0" width="145">
  <tr>
    <td width="16"><img src="about_files/top_lef.gif" alt="a" width="16" height="16">
    </td>
    <td background="about_files/top_mid.gif" height="16">
      <img src="about_files/top_mid.gif" alt="a">
    </td>
    <td width="16">
      <img src="about_files/top_rig.gif" alt="a" width="16" height="16">
    </td>
  </tr>
  <tr>
    <td background="about_files/cen_lef.gif" width="16">
      <img src="about_files/cen_lef.gif" alt="a">
    </td>
    <td align="left" bgcolor="#ffffff" valign="middle">
      <div align="center">
        <img src="{$cat}/thumb/{$num}.jpg" width="114" height="86" border="1">
      </div>
    </td>

    <td background="about_files/cen_rig.gif" width="16">
      <img src="about_files/cen_rig.gif" alt="a">
    </td>
  </tr>
  <tr>
    <td height="16" width="16">
      <img src="about_files/bot_lef.gif" alt="a" width="16" height="16">
    </td>
    <td background="about_files/bot_mid.gif" height="16">
      <img src="about_files/bot_mid.gif" alt="a">
    </td>
    <td height="16" width="16">
      <img src="about_files/bot_rig.gif" alt="a" width="16" height="16">
    </td>
  </tr>
</table>
HTML;

                }
                else {
                   $y = '<table align="center" border="0" cellpadding="0" cellspacing="0" width="145">
      <tr>
        <td width="16"><img src="about_files/top_lef.gif" alt="a" width="16" height="16"></td>
        <td background="about_files/top_mid.gif" height="16"><img src="about_files/top_mid.gif" alt="a"></td>
        <td width="16"><img src="about_files/top_rig.gif" alt="a" width="16" height="16"></td>
      </tr>
      <tr>
        <td background="about_files/cen_lef.gif" width="16"><img src="about_files/cen_lef.gif" alt="a"></td>
        <td align="left" bgcolor="#ffffff" valign="middle"><div align="center">
		<img src="html/images/bekarov.jpg" width="114" height="86" border="1"></font></div></td>

        <td background="about_files/cen_rig.gif" width="16"><img src="about_files/cen_rig.gif" alt="a"></td>
      </tr>
      <tr>
        <td height="16" width="16"><img src="about_files/bot_lef.gif" alt="a" width="16" height="16"></td>
        <td background="about_files/bot_mid.gif" height="16"><img src="about_files/bot_mid.gif" alt="a"></td>
        <td height="16" width="16"><img src="about_files/bot_rig.gif" alt="a" width="16" height="16"></td>
      </tr>
    </table>';
                }
		echo "<td>";
                echo "$y";
                echo "</td>";
	}
	echo "</tr>\n";
}

// Echo page numbers
echo "</table>\n";
for ($i=1;$i <= $total_pages;$i++) {
	if ($i == $page) echo " $i "; else echo " <a href=\"?cat=$cat&page=$i\">$i</a> ";
}
?>


#26 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 28 September 2006 - 08:09 PM

Please don't remove the original topic title, making it worthless for anyone else wanting to solve identical problems




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users