Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to fetch particular data from the table.
Old 10-20-2008, 12:14 PM How to fetch particular data from the table.
Experienced Talker

Posts: 31
Name: Ignatius Vinoth
Trades: 0
Dear Friends,

I have prepared my guestbook entries, but Im stucked with one concept that if I want to display the out put where item_id matches. can u plz suggest where to create the query & how?

HTML Code:
<form method="post" name="guestform" action="viewguestbook.php">
      <input name="nick" type="text" id="nick" size="22" maxlength="30"></td>
     <input name="email" type="text" id="email" size="22" maxlength="30"></td>
     <input type="hidden" name="item_id" value="1" />
     <textarea name="comments" cols="30" rows="10" id="comments"></textarea></td>
      <input name="btnSign" type="submit" id="btnSign" value="Sign Guestbook" class="button" onmouseover="this.className='button_h'" onmouseout="this.className='button'" onClick="return checkForm();">
</form>
PHP Code:
$query = "SELECT nick, email, comments, DATE_FORMAT(date, '%d.%m.%Y'), item_id ".
         "FROM guestbook ".
   "ORDER BY id DESC ".              "LIMIT $offset, $rowsPerPage";  $result = mysql_query($query) or die('Error, query failed. ' . mysql_error());
if(mysql_num_rows($result) == 0)
{
?>
<?php
}
else
{
 while(
$row mysql_fetch_array($result))
 {
  list(
$nick$email$comments$date$item_id) = $row;
iggywiggy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-20-2008, 03:24 PM Re: How to fetch particular data from the table.
Super Talker

Posts: 116
Name: Paul
Location: South Africa
Trades: 0
Not sure if I have fully understood your question, but it sounds like you want to filter the results of the query by item_id, if I have understood you correctly then I think you would need to add a where clause to your sql query, something like this.

Code:
$query = "SELECT nick, email, comments, DATE_FORMAT(date, '%d.%m.%Y'), item_id ".
         "FROM guestbook ". 

         "WHERE item_id = x".
(This WHERE clause can use different operators eg LIKE, =, != etc.)

         "ORDER BY id DESC ".
"LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed. ' . mysql_error());
I hope this helps, and I am not on the wrong track.
__________________
This was my latest holiday in
Please login or register to view this content. Registration is FREE
South Africa.
This was my favorite adventure holiday in
Please login or register to view this content. Registration is FREE
scorpioserve is offline
Reply With Quote
View Public Profile
 
Old 10-20-2008, 06:51 PM Re: How to fetch particular data from the table.
Experienced Talker

Posts: 31
Name: Ignatius Vinoth
Trades: 0
Dear Paul,

Im tring to display the table in view guest page where the the item_id matches. As per your support Im geting below error,

Error, query failed. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BY id DESC LIMIT 0, 10' at line 1

Ignatius
iggywiggy is offline
Reply With Quote
View Public Profile
 
Old 10-23-2008, 05:02 AM Re: How to fetch particular data from the table.
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
Should "id" be "item_id" in the ORDER BY clause?
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 10-23-2008, 01:08 PM Re: How to fetch particular data from the table.
Experienced Talker

Posts: 38
Name: Alan
Trades: 0
The above "WHERE" clause is what you want. The problem you are getting is that he didn't correctly specify the variable.

"x" should be "$x". That is what is causing your error in this case. You can use any variable name as long as the variable is the same type as the field in the table you are querying. For instance, if the "id" field is numeric, then the variable you use should also be numeric and specified without quotes. If the variable is varchar or text, the variable will need to be with quotes.
__________________

Please login or register to view this content. Registration is FREE
alhefner is offline
Reply With Quote
View Public Profile Visit alhefner's homepage!
 
Old 10-23-2008, 03:09 PM Re: How to fetch particular data from the table.
Experienced Talker

Posts: 31
Name: Ignatius Vinoth
Trades: 0
Thanx everybody...
I have sorted out the problem. Its my pleasure to have ppl like you to support me.

Ignatius
iggywiggy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to fetch particular data from the table.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17221 seconds with 12 queries