473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

php code to retrieve latest data from mysql

8
I have the following code and I want to retrieve the latest data from mysql and have it inside a table I have created. Could anyone tell me what's wrong with it?

Thank you in advance for your effort.

<td>Category Name :
</td>
<td><?php
$query= "SELECT * FROM categories;
$result = mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
if ($num>1) {
$to=1;
}else{
$to=$num;
}
$i=0;
while($i<$to){
$categoryname=mysql_result($result,$i,categoryname );
$i++;
}
?></td>
</tr>
Nov 27 '06 #1
4 2023
ronverdonk
4,258 Expert 4TB
Put your code within code, php or html tags, so we can read it! (see Posting Guidelines at top of this forum).

Ronald :cool:
Nov 27 '06 #2
TKB
8
Put your code within code, php or html tags, so we can read it! (see Posting Guidelines at top of this forum).

Ronald :cool:

I'm sorry for the mistake.

I have re-written a code with which I want each time a member logs in and places an order when they click on the view my order button to have results according to their username and password. Could you please help me out?
[php]
<?php
$_SESSION['logged_in'] = TRUE;
$query = "SELECT * FROM categories";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
?>
<select name="categoryname" id="categoryname">
<option value="">&nbsp;</option>
<?php
while ($line = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<option value=\"".$line[0]."\"> ".$line[1]." </option>" ;
}
mysql_free_result($result);

?>
</select>[/php]
Edited to make it READABLE! - Ronald :cool:
Nov 27 '06 #3
ronverdonk
4,258 Expert 4TB
I'm sorry for the mistake.

I have re-written a code with which I want each time a member logs in and places an order when they click on the view my order button to have results according to their username and password. Could you please help me out?
[php]
<?php
$_SESSION['logged_in'] = TRUE;
$query = "SELECT * FROM categories";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
?>
<select name="categoryname" id="categoryname">
<option value="">&nbsp;</option>
<?php
while ($line = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<option value=\"".$line[0]."\"> ".$line[1]." </option>" ;
}
mysql_free_result($result);

?>
</select>[/php]
Edited to make it READABLE! - Ronald :cool:
Do I understand correctly that you want, after a user has clicked on one of the items in the selection list, to display a list of what they have ordered?

And, if so, do you want that (a) immediately after the select option is clicked or (b) after the user hits the submit button?
In the former case (a) you need JavaScript to capture the onclick event, in the latter case (b) you can just handle it via this same script using PHP.

Ronald :cool:
Nov 27 '06 #4
TKB
8
What I want is after a user hits the submit button to display a list of what he/she has ordered.I'm dealing only with php code hence the b paragraph is of my concern.

Awaiting your response with many thanks.

TKB

Do I understand correctly that you want, after a user has clicked on one of the items in the selection list, to display a list of what they have ordered?

And, if so, do you want that (a) immediately after the select option is clicked or (b) after the user hits the submit button?
In the former case (a) you need JavaScript to capture the onclick event, in the latter case (b) you can just handle it via this same script using PHP.

Ronald :cool:
Nov 28 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marc | last post by:
Hello I have a website where I can upload a file via a form. The uploaded file is stored in a MySQL database. When dloading te file I get a save as... dialog box, letting me save the file. But...
1
by: Wild Child | last post by:
Hi, I am trying to find ways to retrieve data by date from a mysql database. What I would like to do is to have the option for people to retrieve a file that was entered in the week before the...
16
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however...
2
by: Randy Jackson | last post by:
First of all, I apologize in advance if this is covered somewhere in a FAQ. I did a Google search, but really couldn't find anything. I'm having a problem with a simple select query. I've got...
0
by: Gert | last post by:
Hi, I need to store a array() of byte to a mysql field. I created a field in mysql of type varbinary. But storing and retrieving gives problems. Please help. The strTemp = EnDeCrypt(txt,...
1
by: Jonathan | last post by:
I have the following query which is retrieving a set of data it is almost what I want but I can not manage to get the result I desire. SELECT r1, r1_dev, r2, r2_dev, date, time FROM output...
2
by: Gawn | last post by:
Hi I am from Thainald and new to PHP/MySQL. I am doing a news website and I can't do the related news, while I can for latest news. My code for latest news is "SELECT * FROM news WHERE...
2
tolkienarda
by: tolkienarda | last post by:
hi all have finnaly figured out how this php script works. i have been trying to modify it for some time but i sturgled because i had no idea what the logic behind it was but finally i figured it...
6
by: fpcreator2000 | last post by:
Hello everyone. I'm having problems with a page I've created that is used to insert data into a database. It uploads two files into two distinct folder, and it takes the filenames and inserts...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.