Jump to content


Photo

Strange problem echo-ing values database


  • Please log in to reply
3 replies to this topic

#1 xoluz

xoluz
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 20 March 2006 - 07:52 AM

Hello there,

I've got some troubles echoing values...

First of all, I have the following form:

<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>

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?

#2 DjMikeS

DjMikeS
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • Location[NL] Alphen aan den Rijn

Posted 20 March 2006 - 08:40 AM

What is it supposed to do?

Looks like a search form ?

#3 xoluz

xoluz
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 20 March 2006 - 08:45 AM

[!--quoteo(post=356601:date=Mar 20 2006, 06:40 PM:name=DjMikeS)--][div class=\'quotetop\']QUOTE(DjMikeS @ Mar 20 2006, 06:40 PM) View Post[/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..

#4 xoluz

xoluz
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 20 March 2006 - 11:27 AM

Okay, so basicly I have the following code:

Searchform on page1.php
<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>

People should enter carbrand in the textfield, like 'BMW' or 'Ford'. Then they press 'Search' and they should go to page2.php.

Page2.php looks like this:
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)) {

Now that was the PHP-code. When I want to echo something, I use this code:
<?php print "$row->carnumber"; ?>
<?php print "$row->carbrand"; ?>
<?php print "$row->cardescription"; ?>
<?php print "$row->carprice"; ?>

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:

1         |       B       |        T          |          2
1         |       B       |        T          |          2
3         |       B       |        T          |          3
8         |       B       |        P          |          1

Instead of this:

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,-

See, it's only echoing the first character.. ;(

edit: problem solved, I shouldn't use the foreach command.. :P




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users