Jump to content

Strange problem echo-ing values database


xoluz

Recommended Posts

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
Share on other sites

[!--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
Share on other sites

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          |          2
1         |       B       |        T          |          2
3         |       B       |        T          |          3
8         |       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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.