473,404 Members | 2,195 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,404 software developers and data experts.

mysql values to display on PHP form

ddtpmyra
333 100+
Hi,

Im looking for sample code that will retrieve the values from mysql query. Most of my code has the "while($row = mysql_fetch_assoc($result))" and that will display the values by rows. How about the display are in indent format?


Belowi s the input text box that I wanted to show the values from mysql query. Anybody can show me how not using the while function?
Expand|Select|Wrap|Line Numbers
  1.  
  2. <td>Total English</td>
  3.       <Input type = 'text' Name ='TotalSTSEnglish' value='0' >
  4. <td>Total Spanish</td> 
  5.       <Input type = 'text' Name ='TotalSTSEnglish' value='0' >   
Jun 17 '09 #1
8 2713
ak1dnar
1,584 Expert 1GB
The while() loop will keep fetching new rows until mysql_fetch_assoc() returns FALSE, which means there are no more rows to fetch.
So if you only need to get one row from your mysql query (assuming your query returns only one row) here is the solution.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. mysql_connect("localhost","root","") or die(mysql_error());
  3. mysql_select_db("books");
  4. $result = mysql_query("select * from books "); // You can put your where clause here 
  5. $row = mysql_fetch_assoc($result);
  6. $book_name =  $row['name'];
  7. ?>
  8.  
Now print the variables inside the value attribute on the input box. hope this will help. Thanks
Jun 18 '09 #2
Dormilich
8,658 Expert Mod 8TB
you may also look at PDO's fetch*() methods.
Jun 18 '09 #3
ddtpmyra
333 100+
Thanks ak1dnar it works!
I appreciate the knowledge shared :)
@ak1dnar
Jun 22 '09 #4
ddtpmyra
333 100+
A follow-up question on this topic... now I have a check box but Im having problem to pull the information. Inside the talbe the field value = 1, how come it wont display?

Expand|Select|Wrap|Line Numbers
  1. <table width='80%' border='0' summary=''>";
  2.     $result = mysql_query("select Total from recap where Cal_ID={$id} and category='Target Focus'  ");
  3.     $row = mysql_fetch_assoc($result);
  4.     $Total =  $row['Total'];
  5.     echo "<td><input type = 'checkbox' name ='Community' value='$row[Total]'/>Disabled Community </tr></td>";
  6.     echo "<tr>";                            
  7. echo "</table>
  8.  
Jun 24 '09 #5
ak1dnar
1,584 Expert 1GB
check box values doesn't appear as the HTML output , did you check the generated html source from the browser view source option ?
Jun 25 '09 #6
ddtpmyra
333 100+
I check my sql and the value is 1. And yet still no check apeared.


PHP
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("select Total from tblevent_recap where Cal_ID={$id} and category='Target Focus' and Name ='Disabled Community' ");
  2. $row= mysql_fetch_assoc($result);
  3. if(mysql_num_rows($result)!=0) {
  4. echo "<td><input type = 'checkbox' name ='DisabledCommunity' value='checked'>Disabled Community </tr></td>";
  5. echo "<tr>";  }
  6. else 
  7. echo "<td><input type = 'checkbox' name ='DisabledCommunity' value=''>Disabled Community </tr></td>";
  8. echo "<tr>";
  9. }
  10.  
  11.  
I veiwed the HTML
Expand|Select|Wrap|Line Numbers
  1. ><input type = 'checkbox' name ='DisabledCommunity' value='checked'>Disabled Community </tr></td><tr><td>
Jun 25 '09 #7
Markus
6,050 Expert 4TB
The correct attribute is 'checked'.

Expand|Select|Wrap|Line Numbers
  1. <input type='checkbox' checked='checked' />
  2.  
Jun 25 '09 #8
ak1dnar
1,584 Expert 1GB
I think you may better to follow these tutorials on HTML form markup.
http://www.w3schools.com/html/html_forms.asp
Jun 26 '09 #9

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

Similar topics

5
by: apchar | last post by:
I am trying to use php as a kind of servlet to act as a middle man between a java applet and mysql. I know java has jdbc but it's flakey and painful. php access to mysql is much nicer. So I have:...
3
by: spacemancw | last post by:
I'm reading an article on MySQL/PHP at http://hotwired.lycos.com/webmonkey/99/21/index3a_page4.html?tw=programming It's very good for me starting out but I have a question. I'm using OS X...
2
by: Matthew Clubb | last post by:
Hi, I need help developing an expanding form I've decided that a use of PHP, Mysql and Javascript is the best platform for creating a selection of database interfaces which I'm trying to build...
3
by: Stephen Preston | last post by:
I can't get an $array to be used as a select query on a mySQL database. I have a 'parts list' which displays on a page (works fine) and is a form. At the end of each row is a input type='text'...
1
by: mpar612 | last post by:
Hi everyone, I'm not sure if this is asking too much or not. I am trying to get the following PHP code to work on my website. It utilizes PHP 5, MySQL 4.1 and the PEAR DB module. I am...
2
by: drakorq | last post by:
I got stuck on this, and it would be really great if anybody could point me in the right direction. I was trying setting up these scripts following instructions in a book from 2003, so I thought...
1
by: PowerLifter1450 | last post by:
I've been having a very rough time installinig mySQL on Linux. I have been following the instructions form here: http://www.hostlibrary.com/installing_apache_mysql_php_on_linux Everytime I get to...
7
by: dongletran06 | last post by:
Hi, Please help me find out what wrong with my codes in inputting from my form to mysql database using drop down menu. Below is the codes I used. Only the drop down is not working but the "input...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
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?
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...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.