473,386 Members | 1,795 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,386 software developers and data experts.

printing only data in a spcific row of a mysql table using php

tolkienarda
316 100+
hi all i have gotten a table from a mysql database and stored into $request
in this table there is an 'id' field which is unique and auto incrimenting and a name field. i am doing a loop to display all of the names of the people in a <select> drop down box. i have written some code with english to fill in the blanks if someone could replace my english with php code i would appreciate it.
hereis the first set
[PHP]
$result=mysql_query("SELECT id, name, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eight FROM Students")
$row=mysql_num_rows($result);
[/PHP]
and the actual code
[PHP]
<form>
<select>
<?
$i=1;
while($i > $row)
{

$temp=(the name of the person stored in the row with the corasponding id);

if($temp = (if a record gets deleted then there will be a gap in 'id' and this value will be 0 or null not sure which)
{
$i++;
}
else
{
echo "<option>"$temp"</option>";
$i++;
}
}
?>
</select>
</form>
[/PHP]
Jan 10 '07 #1
6 1843
b1randon
171 Expert 100+
hi all i have gotten a table from a mysql database and stored into $request
in this table there is an 'id' field which is unique and auto incrimenting and a name field. i am doing a loop to display all of the names of the people in a <select> drop down box. i have written some code with english to fill in the blanks if someone could replace my english with php code i would appreciate it.
hereis the first set
[PHP]
$result=mysql_query("SELECT id, name, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eight FROM Students")
$row=mysql_num_rows($result);
[/PHP]
and the actual code
[PHP]
<form>
<select>
<?
$i=1;
while($i > $row)
{

$temp=(the name of the person stored in the row with the corasponding id);

if($temp = (if a record gets deleted then there will be a gap in 'id' and this value will be 0 or null not sure which)
{
$i++;
}
else
{
echo "<option>"$temp"</option>";
$i++;
}
}
?>
</select>
</form>
[/PHP]
[PHP]
<form>
<select>
<?
while ($row = mysql_fetch_row($result)) {
echo "<option>"$row[name]"</option>";
}
?>
</select>
</form>
[/PHP]
Jan 10 '07 #2
ronverdonk
4,258 Expert 4TB
As long as you understand that this select is doing nothing when an option is clicked, just displaying some names, I'll show you. But don't come back after this to expand this sample into a full-fledged application!
[php]<?
$result=mysql_query("SELECT id, name, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eight FROM Students")
or die("Select error: ".mysql_error());
echo '<form>';
echo '<select>';
while ($row=mysql_fetch_assoc($result)) {
$temp=$row['name'];
echo "<option value='$temp'>$temp</option>";
}
?>
</select>
</form>[/php]
Ronald :cool:
Jan 10 '07 #3
ronverdonk
4,258 Expert 4TB
Sorry Brandon, I didn't know you were also replying to this post.

Ronald :cool:
Jan 10 '07 #4
tolkienarda
316 100+
thank you much next question:


after someone has selected the desired name out of the select box i need to get the rest of the information stored in that row. here is what i used for the <option>

[PHP]
echo "<option value=' "$row[id]" '>"$row[name]"</option>";
[/PHP]
now a function is called that recives the value from here there are several other pices of data i need from that row
Jan 10 '07 #5
ronverdonk
4,258 Expert 4TB
You did not make that <option> yourself, it was posted in this forum by b1randon. Now what have you developed yourself, or have been trying to develop yourself, to obtain and display that information?

As I said in a previous post, you cannot use 'salami-tactics' to let our members develop a full-fledged application for you from the ground up. You'll have to do something yourself.

So please show us your code!

Ronald :cool:
Jan 10 '07 #6
tolkienarda
316 100+
Here is my code. I am not trying to take credit for code i didn't write myself. took the code b1randon wrote and changed one small detail. sorry if i offended anyone. anywhy i downloaded some of this code from another site this stuff is commented. i only changed variable names on these lines. on the non commented lines i either wrote them myself or was directed by one of the posts in this thread

the places where there are text in () instead of code are places i can't figure out if you think that i am asking for too much then mabey you could point me toward a tutorial that i could read. i am more than willing to do that and i have in the past but some of them leave out the simple stuff because they figure that most people already know how to do them

[PHP]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<?
session_start(); // Use session variable on this page. This function must put on the top of page.
if(!session_is_registered("username")){ // if session variable "username" does not exist.
header("location:index.php"); // Re-direct to index.php
}
?>
<?


// Connect database.
$host="localhost"; // Host name.
$db_user="rcadmin"; // MySQL username.
$db_password="nsds2004"; // MySQL password.
$database="RCA"; // Database name.
$RCA = mysql_pconnect($host, $db_user, $db_password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database, $RCA);

$result=mysql_query("SELECT id, Login name, class1, class2, class3, class4, class5, class6, class7, class8 FROM Students")
$row=mysql_num_rows($result);

function selectclass($tempstudent)
{
$therow = row that corosponds with that name
$displayclsses=1;
$login=the Login of the peron whos name is stored in $tempstudent
}
function disp($tempclass)
{
$assignments=mysql_query("SELECT ID, student, class1, class2, class3, class4, class5, class6, class7, class8 FROM assignments WHERE student='$login'")
$grades=mysql_query("SELECT ID, student, class1, class2, class3, class4, class5, class6, class7, class8 FROM grades WHERE student='$login'")
$comments=mysql_query("SELECT ID, student, class1, class2, class3, class4, class5, class6, class7, class8 FROM comments WHERE student='$login'")
}
?>
</head>

<body>
<p>Hello teacher <? echo $_SESSION['user'];?>! You are now Logged in.</p>
<p><a href="login.php">Logout</a></p>
<form method="post" action="$func">
<select>
<option>asdf</option>
<?
while ($row = mysql_fetch_row($result))
{
echo "<option value='"$row[name]"'>"$row[name]"</option>";
}
$func="selectclass";
?>
</select>
<?

if($displayclasses=1)
{
<select>
$i=1;

while($i<9)
{
$temp=the class name
if ($temp!=null or whatever)
{
echo '<option value="'$temp'">'$temp'</option>';
}
}
</select>
}
func="disp";
?>
<?
echo '<input type="text" maxlength="5" name="grade" id="grade" value="grade">';
echo '<textarea name="assignments" rows="16" cols="65" id="assignments" value='(assignment value for that student and class)' />';
echo '<textarea name="comments" rows="16" cols="65" id="comments" />'
$func="update";
?>

</form>
</body>
</html>
[/PHP]
Jan 11 '07 #7

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

Similar topics

0
by: Luc Foisy | last post by:
Last week many of our server and client servers had a power problem. Not = quite sure how the servers were handled, wasn't on site, but I don't = think some of these servers got shut down...
12
by: Jerry Weinstein | last post by:
Hi, I know about stored procedures and that they can speed up data entry via the SQL 'insert ' statement. However, one drawback to this method is that using the stored procedure still requires...
6
by: Kamilche | last post by:
I have a large project that is getting complex, and I would like to print the docstrings without importing the modules. The only Python utility I could find references is apparently defunct and...
3
by: nsh | last post by:
mailing.database.mysql, comp.lang.php subject: does "LOAD DATA" EVER work?!? I've tried EVERYTHING! version info: my isp is running my web page on a linux box with php ver. 4.4.1 according to...
3
by: eieiohh | last post by:
MySQL 3.23.49 PHP 4.3.8 Apache 2.0.51 Hi All! Newbie.. I had a CRM Open Source application installed and running. Windows Xp crashed. I was able to copy the contents of the entire hard...
1
by: JackM | last post by:
I'm not sure if this qualifies as a mysql or a php question so I'm asking in both groups. I am pulling the results of a mysql query from my database and want to print the results into a two...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
29
by: FredBear | last post by:
I am just coming to grips with php, Dreamweaver and MySQL and I want to make a facility available for the members of the group I am creating my web site for. I want them to be able to print-out a...
2
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.