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
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.

Link to comment
Share on other sites

From your reply I assume you've found the answer elsewhere but since I notice this I may as well mention the need to use a loop similar to the following to retrieve each row in the result set.

while ($ai = mysql_fetch_array($r1))
{
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.