The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
form values
Discuss form values in the PHP Development forum on Dev Shed. form values PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 29th, 2000, 01:38 AM
|
|
The Dude Abides
|
|
Join Date: Feb 2000
Location: grass valley,ca
Posts: 1,062
Time spent in forums: 1 Day 10 h 1 m 34 sec
Reputation Power: 15
|
|
|
Need a little help. I'm trying to print search results from a mysql database. In the results I need the following:
print ("<INPUT TYPE="CHECKBOX" NAME="addit" VALUE="item description^price^1">")
the info in the value area needs to be called from a mysql database. The ^ symbols need to be between each of the mysql results. I've tried a few different methods but none seem to display the results.
Suggestions???
Thanks in advance
------------------
Chris Staniar
|

February 29th, 2000, 08:22 AM
|
|
Contributing User
|
|
Join Date: Jan 2000
Posts: 79
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
Why would u want to put more than 1 results in as the default value for a checkbox anyway?
Basil
|

February 29th, 2000, 11:45 AM
|
|
Junior Member
|
|
Join Date: Feb 2000
Location: durham, nc, usa
Posts: 14
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
I am not sure I understand the poster's question. You are having trouble outputting your parse delimiters (^)? or you are having trouble getting proper html output in general?
When I do something like this I am generally in a loop outputting html table rows for (for instance) a shopping cart. I have the results of my SQL query in separate variables (i.e., $sku, $qty, $description, etc.) and use printf with an appropriate format string.
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>printf ("<tr><td><input type=checkbox name="addit[]" value = "%s^%d^">%s</td></tr>n", $description, $price, $description);[/code]
It's freehand, so it may be a little whacky. If so, I'll correct it as soon as I get home, but it should work out and output something like
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><tr><td><input type=checkbox name=addit[] value = "testitem^2.23^>testitem</td></tr>[/code]
You may want to reexamine the value field, which looks as though you're trying to combine a key with a price. If this info is in your base already, why not just pass the sku number (or whatever)?
Also, If you're dealing with multiple items, be sure to name the checkbox with name = "addit[]" or whatever so that it knows to send PHP an array of items. good luck.
jim
[This message has been edited by jodonnell (edited February 29, 2000).]
[This message has been edited by jodonnell (edited February 29, 2000).]
|

March 1st, 2000, 12:15 AM
|
|
The Dude Abides
|
|
Join Date: Feb 2000
Location: grass valley,ca
Posts: 1,062
Time spent in forums: 1 Day 10 h 1 m 34 sec
Reputation Power: 15
|
|
|
Sorry, I should have been more specific. The value of the checkbox needs to be this way in order to pass data to a shopping cart. The ^ symbols break up the data so the shopping cart can utilize the data. The ^ symbols are not going to be printed from the database, only the product description and price.
Where you see description^price these need to be separate values called from a mysql db. Below is a more detailed section of the code.
Thanks
mysql_select_db (chrisdb);
if ($prodname == "")
{$prodname = '%';}
$result = mysql_query ("SELECT * FROM products
WHERE prodname LIKE '$prodname%'
");
if ($row = mysql_fetch_array($result)) {
do {
print ("<TR><TD>");
print ("<INPUT TYPE="CHECKBOX" NAME="addit" VALUE="description^price^1"></TD>");
print ("<TD>");
print $row["prodname"];
print ("</TD><TD>");
print $row["description"];
print ("</TD><TD>");
print $row["price"];
print ("</TD><TD><INPUT TYPE="submit" VALUE="Order"></TD></TR></TABLE>");
} while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}
|

March 1st, 2000, 07:46 AM
|
|
Contributing User
|
|
Join Date: Apr 1999
Location: London
Posts: 110
Time spent in forums: 22 m 26 sec
Reputation Power: 0
|
|
|
the following code should do it, its only a couple of changes to your original...
<?
mysql_connect("whatever");
$result = mysql_db_query ("databasename","SELECT * FROM products WHERE prodname LIKE '$prodname%'");
if ($row = mysql_fetch_array($result))
{
do
{
print ("<TR><TD>");
print ("<INPUT TYPE="CHECKBOX" NAME="addit" VALUE="".$row["0"]."^".$row["1"]."^".$row["2"].""></TD>");
print ("<TD>");
print $row["0"];
print ("</TD><TD>");
print $row["1"];
print ("</TD><TD>");
print $row["2"];
print ("</TD><TD><INPUT TYPE="submit" VALUE="Order"></TD></TR></TABLE>");
}
while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}
?>
hth
timbo
sorry should have said just replace the "0" "1" etc with whatever your column names are
------------------
cheers
[This message has been edited by timbo (edited March 01, 2000).]
|

March 2nd, 2000, 12:28 AM
|
|
The Dude Abides
|
|
Join Date: Feb 2000
Location: grass valley,ca
Posts: 1,062
Time spent in forums: 1 Day 10 h 1 m 34 sec
Reputation Power: 15
|
|
|
Thanks, that worked great!
------------------
Chris Staniar
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|