xoluz Posted March 20, 2006 Share Posted March 20, 2006 Hello there,I've got some troubles echoing values...First of all, I have the following form:[code]<form name="form" method="POST"><table width="806" border="0"> <tr> <td width="160">Number</td> <td width="211">Description</td> <td width="153">Price / Amount</td> </tr><?php$number = ($_POST['number']);$query = "select * from cars where number='$number'"; $result = mysql_query($query);while ($row = mysql_fetch_object($result)) {foreach ($row AS $array) {?> <tr> <td><?php echo $array["carnumber"]; ?></td> <td><?php echo $array["cardescription"]; ?></td> <td><?php echo $array["carppamount"]; } }?></td> </tr></table></form>[/code]But it's not really working, because it's only echo-ing the first letter of the value from the database :S. Does anyone know how that happened? Link to comment https://forums.phpfreaks.com/topic/5332-strange-problem-echo-ing-values-database/ Share on other sites More sharing options...
DjMikeS Posted March 20, 2006 Share Posted March 20, 2006 What is it supposed to do?Looks like a search form ? Link to comment https://forums.phpfreaks.com/topic/5332-strange-problem-echo-ing-values-database/#findComment-18987 Share on other sites More sharing options...
xoluz Posted March 20, 2006 Author Share Posted March 20, 2006 [!--quoteo(post=356601:date=Mar 20 2006, 06:40 PM:name=DjMikeS)--][div class=\'quotetop\']QUOTE(DjMikeS @ Mar 20 2006, 06:40 PM) [snapback]356601[/snapback][/div][div class=\'quotemain\'][!--quotec--]What is it supposed to do?Looks like a search form ?[/quote]No, I have a form where I enter this carnumber. That form is linked to the form I posted before. It should display all cars and stuff, but it's only displaying the first letter of all cars.. Link to comment https://forums.phpfreaks.com/topic/5332-strange-problem-echo-ing-values-database/#findComment-18988 Share on other sites More sharing options...
xoluz Posted March 20, 2006 Author Share Posted March 20, 2006 Okay, so basicly I have the following code:[b]Searchform on page1.php[/b][code]<form name="form" method="post" action="page2.php"><input name="carbrand" type="text" size="16" maxlength="16"></td><input type="submit" name="Submit" value="Search"></form>[/code]People should enter carbrand in the textfield, like 'BMW' or 'Ford'. Then they press 'Search' and they should go to page2.php.[b]Page2.php looks like this:[/b][code]include 'connect_to_db.php';$carbrand = ($_POST['carbrand']);$mysql_query = "SELECT * FROM carbrands WHERE carbrand='$carbrand'"; $result = mysql_query($mysql_query);while ($row = mysql_fetch_object($result)) {[/code]Now that was the PHP-code. When I want to echo something, I use this code:[code]<?php print "$row->carnumber"; ?><?php print "$row->carbrand"; ?><?php print "$row->cardescription"; ?><?php print "$row->carprice"; ?>[/code]Goal: I want to show ALL cars of the brand what was inserted before on the form of page1.php.Problem: The code is working, BUT it's only showing the first character of the value in the database. So I get this:[code]1 | B | T | 21 | B | T | 23 | B | T | 38 | B | P | 1[/code]Instead of this:[code]13344 | BMW | This is a BMW 318i | 21000,-13367 | BMW | This is a BMW 325Ci | 28000,-34344 | BMW | This is a BMW 325M3 | 31000,-89333 | BMW | Perfect BMW 525 | 19999,-[/code]See, it's only echoing the first character.. ;(edit: problem solved, I shouldn't use the foreach command.. :P Link to comment https://forums.phpfreaks.com/topic/5332-strange-problem-echo-ing-values-database/#findComment-18998 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.