Jump to content


Photo

simple display in table question


  • Please log in to reply
4 replies to this topic

#1 puja

puja
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 08 May 2006 - 02:43 PM

hi
im trying to get some values to be shown in a table and im sure most of you are thinking duh that is really easy but im having a mental block with it.
i know how to get multiple lines to show but i only want the one specific line of results to show for the current variables.

the code is:
    $type = $_POST["select_type"];
    $sleeps = $_POST["select_sleeps"];
    $board = $_POST["select_board"];
    $pets_allowed = $_POST["select_pets_allowed"];

$query3 = "(SELECT accommID, type, sleeps, board, description, pets_allowed, price FROM accommodation WHERE type='$type' && sleeps = '$sleeps' && board='$board' && pets_allowed ='$pets_allowed')";
            $result3 = mysql_query ($query3) or die(mysql_error());

            //$num = mysql_num_rows($result3);
            //$num = 0;
            //if ($num > 0)
                //{
                echo '<FORM METHOD="POST" ACTION="add_pay.php">';
                echo '<table align = "center" border = "1" cellspacing = "0" cellpadding = "5">
                    <tr>
                         <td align="left"><b>Type</b></td>
                         <td align="left"><b>Sleeps</b></td>
                         <td align="left"><b>Board</b></td>
                         <td align="left"><b>Description</b></td>
                         <td align="left"><b>Pets Allowed</b></td>
                         <td align="left"><b>Price</b></td>

                         </tr>
                         ';
                          echo '
                          <tr>
                         <td align="left">'. $type. '</td>
                         <td align="left">'. $sleeps. '</td>
                         <td align="left">'. $board. '</td>
                         <td align="left">'. description. '</td>
                         <td align="left">'. $pets_allowed. '</td>
                         <td align="left">'. price. '</td>
                         </tr>
                         ';

                echo '</table>';
                echo ' ';
                echo '<center> <input type="submit" value="Confirm Booking"></center>';
                echo '</FORM>';


description and price should be taken straight from the table
thanks

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 08 May 2006 - 03:12 PM

You never fetch the data:

$row = mysql_fetch_array($result);

I also don't know what you mean by your last statement.

Info: PHP Manual


#3 puja

puja
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 08 May 2006 - 03:42 PM

sorry i didnt explain myself very well there
all the other fields are php variables that have some data stored on them but description and price are not variables, i just need to to insert whatever is in the table for that row where the other variables are from
(not sure if that explaination is any better!)

code has now been changed to:

    $type = $_POST["select_type"];
    $sleeps = $_POST["select_sleeps"];
    $board = $_POST["select_board"];
    $pets_allowed = $_POST["select_pets_allowed"];

$query3 = "(SELECT accommID, type, sleeps, board, description, pets_allowed, price FROM accommodation WHERE type='$type' && sleeps = '$sleeps' && board='$board' && pets_allowed ='$pets_allowed')";
            $result3 = mysql_query ($query3) or die(mysql_error());

            $row = mysql_fetch_array($result3);

            //$num = 0;
            //if ($num > 0)
                //{
                echo '<FORM METHOD="POST" ACTION="add_pay.php">';
                echo '<table align = "center" border = "1" cellspacing = "0" cellpadding = "5">
                    <tr>
                         <td align="left"><b>Type</b></td>
                         <td align="left"><b>Sleeps</b></td>
                         <td align="left"><b>Board</b></td>
                         <td align="left"><b>Description</b></td>
                         <td align="left"><b>Pets Allowed</b></td>
                         <td align="left"><b>Price</b></td>

                         </tr>
                         ';
                          echo '
                          <tr>
                         <td align="left">'. $row['type']. '</td>
                         <td align="left">'. $row['sleeps']. '</td>
                         <td align="left">'. $row['board']. '</td>
                         <td align="left">'. $row['description']. '</td>
                         <td align="left">'. $row['pets_allowed']. '</td>
                         <td align="left">'. $row['price']. '</td>

                         </tr>
                         ';

                echo '</table>';
                echo ' ';
                echo '<center> <input type="submit" value="Confirm Booking"></center>';
                echo '</FORM>';



#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 08 May 2006 - 05:50 PM

Umm... that's still confusing, but if I understand you correctly, you should change it to this:
<td align="left">'. $row['type']. '</td>
                         <td align="left">'. $sleeps . '</td>
                         <td align="left">'. $board . '</td>
                         <td align="left">'. $row['description']. '</td>
                         <td align="left">'. $pets_allowed. '</td>
                         <td align="left">'. $row['price']. '</td>

Info: PHP Manual


#5 puja

puja
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 08 May 2006 - 07:42 PM

no that still doesnt work

what i was trying to explain was that the $type, $board, $sleeps and $pets_allowed have come from the choices that the user has made.
however the description and price are not choices. they should just be the fields in the database for the row that was chosen for those choices




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users