PDA

View Full Version : missing something...not sure what...



jasonhardwick
August 30th, 2007, 12:17 PM
can anyone see what is wrong with this code im sure there is more than one problem.



<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$query = 'select * from press order by date desc limit 20, 1000';
or die(mysql_error());
$title = 'title';
$date = 'date';
$body = 'body';
$cover = 'cover' ? '<img src="' . 'cover' . '">' : '';

print <<<EOHTML
<tr>
<td align="left" valign="top"><p><b>$title</b><br />$date</p>
<p>$cover</p></td>
<td><p>$body</p></td>
</tr>
<tr>
<td height="20">&nbsp;</td>
<td><hr /></td>
</tr>
EOHTML;
mysql_close();
?>

Charleh
August 30th, 2007, 12:22 PM
Yeah first off you've got

or die(mysql_error());
after $query = 'select * from press order by date desc limit 20, 1000';

Well that's just a variable assignment - and plus you are terminating the line with a semicolon so the "or die(mysql_error());" is an orphaned fragment of code which won't work.

Also the mysql stuff doesn't actually run a query

jasonhardwick
August 30th, 2007, 12:25 PM
ok, I am taking bits from other code to make it work. not a php guy ,any help on running the proper query?

jasonhardwick
August 30th, 2007, 03:28 PM
any help?

jasonhardwick
August 30th, 2007, 05:49 PM
<?php

mysql_connect("XXXX", "XXXX", "XXXX") or die(mysql_error());
mysql_select_db("XXXX") or die(mysql_error());

$query = 'select * from press order by date desc limit 20, 1000'
or die(mysql_error());

$title = 'title';
$date = 'date';
$body = 'body';
$cover = 'cover' ? '<img src="' . 'cover' . '">' : '';

print <<<EOHTML
<tr>
<td align="left" valign="top"><p><b>$title</b><br />$date</p>
<p>$cover</p></td>
<td><p>$body</p></td>
</tr>
<tr>
<td height="20">&nbsp;</td>
<td><hr /></td>
</tr>
EOHTML;

mysql_close();
?>

hl
August 30th, 2007, 09:12 PM
Patience bro.



$query = 'select * from press order by date desc limit 20, 1000'
or die(mysql_error());


You just need a [d-php]mysql_query[/d-php] so:


$query = 'SELECT * FROM `press` ORDER BY `date` DESC LIMIT 20,1000';
mysql_query($query) or die(mysql_error());

Additionally, you're not really doing anything with the data or so it seems. Take a look at [d-php]mysql_fetch_assoc[/d-php].

jasonhardwick
August 31st, 2007, 12:07 PM
Thanks now can anyone help me resize the image out put to force it to 100 px wide x proper height %



<?php

$conn = mysql_connect("XXXX", "XXXX", "XXXX");

if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}

if (!mysql_select_db("XXXX")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}

$sql = "SELECT *
FROM press
ORDER BY date
DESC LIMIT 0,1000";

$result = mysql_query($sql);

if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}

if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
echo "<TABLE cellspacing=\"40\" cellpadding=\"5\">";
while ($row = mysql_fetch_assoc($result)) {
$cover = $row["cover"] ? '<img src="' . $row["cover"] . '">' : '';

echo "<TR>";
echo "<TD width=\"100\" align=\"right\" valign=\"top\" <span class=\"style1\">".$cover;
echo "<br/><br/>";
echo $row["date"];
echo "<br/>";
echo $row["title"]."</span></TD>";
echo "<TD align=\"left\" valign=\"top\" <span class=\"style3\">".$row["body"]."</TD>";
echo "</TR>";

}

echo "</TABLE>";

mysql_free_result($result);

?>

jasonhardwick
August 31st, 2007, 07:46 PM
anyone have any ideas on this??