Echo this?

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

Echo this?

Postby timstring » 05. October 2010 02:36

How do I write this HTML statement in PHP:

Code: Select all
<td width="26"><p>2</p></td>


where <p>2</p> should be information from a MySQL table?

I have tried:

Code: Select all
 echo "<td width=\'26\'>" . $row['S1'] . "</td>";


and

Code: Select all
  echo "<td width=\"26\">" . $row['S1'] . "</td>";


and all that gets echoed is

" . $row['S1'] . "


What am I missing?
tim
"If builders built buildings the way that programmers write programs, the first woodpecker to come along would destroy civilization."
User avatar
timstring
 
Posts: 22
Joined: 17. September 2010 02:16

Re: Echo this?

Postby Altrea » 05. October 2010 06:54

short_open_tags?
wrong file extension?
wrong file requesting?

tell us more to get more
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Echo this?

Postby timstring » 06. October 2010 02:12

You asked for it...... The output looks like I have an open quote without a closed quote, but I don't see one anywhere.


Code: Select all
<?php

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("BTS", $con);





$result = mysql_query("SELECT * FROM `Worksheet` WHERE Date = $_POST['Date'])");

while($row = mysql_fetch_array($result))
  {

          echo "<tr>";
          echo "<td>" . $row['Job'] . "</td>";
          echo "<td>" . $row['Account'] . "</td>";
          echo "<td>" . $row['Address'] . "</td>";
          echo "<td>" . $row['Equipment'] . "</td>";
          echo "<td>" . $row['First'] . "</td>";
          echo "<td>" . $row['S1'] . "</td>";
          echo "<td>" . $row['S2'] . "</td>";
          echo "<td>" . $row['S3'] . "</td>";
          echo "<td>" . $row['S4'] . "</td>";
          echo "<td>" . $row['S5'] . "</td>";
          echo "<td>" . $row['S6'] . "</td>";
          echo "<td>" . $row['S7'] . "</td>";
          echo "<td>" . $row['S8'] . "</td>";
          echo "<td>" . $row['S9'] . "</td>";
          echo "<td>" . $row['S10'] . "</td>";
          echo "<td>" . $row['S11'] . "</td>";
          echo "<td>" . $row['S12'] . "</td>";
          echo "<td>" . $row['COD'] . "</td>";
                   
               echo "</tr>";
  }
     
  mysql_close($con)
?>     
"If builders built buildings the way that programmers write programs, the first woodpecker to come along would destroy civilization."
User avatar
timstring
 
Posts: 22
Joined: 17. September 2010 02:16

Re: Echo this?

Postby Altrea » 06. October 2010 05:25

timstring wrote:You asked for it......

Sure. The only possibility to debug a script you don't know is to see it.

$result = mysql_query("SELECT * FROM `Worksheet` WHERE Date = $_POST['Date'])");

There is a additional ) After your $_POST Variable.
And you should use backticks on all of your Table-Colums (Date could be a preregistered MySQL word)
And you should add some error handling like
Code: Select all
if (!$result) {
    //... do something (e.g. echo the mysql_error())
}

And you should add some debug output (does the query return a valid mysql collection? how many rows are selected?

Code: Select all
while($row = mysql_fetch_array($result))

You can use mysql_fetch_assoc instead of mysql_fetch_array, if you just need the associated array
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for macOS

Who is online

Users browsing this forum: No registered users and 10 guests