Jump to content

[SOLVED] I cannot get mysql limit !!!


balkan7

Recommended Posts

hi all

i have problem i was try many times to get more records from date base, can someone help me to get limited records.

 

here is my code:

 

sql

CREATE TABLE `bsoft_catalog` (
  `ItemID` int(10) NOT NULL auto_increment,
  `ItemName` varchar(255) NOT NULL default '',
  `ItemDesc` text NOT NULL,
  `ItemPrice` float(10,2) NOT NULL default '0.00',
  `ItemImage` text NOT NULL,
  `ItemCategory` int(10) NOT NULL default '0',
  `ItemCd` int(10) NOT NULL default '0',
  `Novo` varchar(50) NOT NULL default '',
  `Datum` date NOT NULL default '0000-00-00',
  PRIMARY KEY  (`ItemID`),
  UNIQUE KEY `ItemName` (`ItemName`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

CREATE TABLE `bsoft_categories` (
  `CategoryID` int(10) NOT NULL auto_increment,
  `CategoryName` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`CategoryID`),
  UNIQUE KEY `CategoryName` (`CategoryName`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

 

php code:

<?php
include_once("conn.php");
include_once("lang/eng.php");
include_once("includes.php");

include_once("templates/HeaderTemplate.php");

$q1 = "select * from bsoft_catalog, bsoft_categories ORDER BY ItemID DESC limit 4";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) > '0')
{
$a1 = mysql_fetch_array($r1);

if(empty($a1[itemImage]))
{
	$ItemImage = "<img src=\"no_image.gif\" width=\"145\" alt=\"No Picture!\" border=0>";
}
else
{
	$size = getimagesize("items_images/$a1[itemImage]");

	if($size[0] > 120)
	{
		$width = 120;
		$height = 100;
	}
	else
	{
		$width = $size[0];
		$height = $size[0];
	}

	$ItemImage = "<img src=\"items_images/$a1[itemImage]\" width=\"$width\" height=\"$height\" alt=\"$a1[itemName]\" border=0>";
}

include_once("templates/IndexTemplate.php");
}

include_once("templates/FooterTemplate.php");

?>

Link to comment
https://forums.phpfreaks.com/topic/36966-solved-i-cannot-get-mysql-limit/
Share on other sites

$q1 = "select * from bsoft_catalog, bsoft_categories ORDER BY ItemID DESC limit 4";

 

It appears as though you're trying to JOIN the two tables above. If that's the case, then from the CREATE statements for the tables I think the following query would be more appropriate

SELECT
*
FROM
bsoft_catalog AS clog
INNER JOIN
bsoft_categories AS cgory
ON
clog.ItemCategory = cgory.CategoryID
ORDER BY
ItemID DESC

 

hi all

i have problem i was try many times to get more records from date base, can someone help me to get limited records.

 

If you'd like to retrieve more records omit/remove the "LIMIT 4" from the end of the query as I've done above.

 

One other thing that I notice is that your code does not use the Category Name. If you're not using it you should consider not joining the tables as that's the only additional information that is retrieved from the category table.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.