PDA

Click to See Complete Forum and Search --> : Here's another Q....


carp
Jul 29th, 2002, 09:39 PM
Parse error: parse error, unexpected T_INC in /home/djstop/public_html/test/phatfx.php on line 322

my code:


<?

myconnect();


$query = "SELECT * FROM `songs` ORDER BY `id` DESC";
$result = mysql_query($query);
$rows = @mysql_num_rows($result);

$foundentries = false;

while ($i < $rows) {
$foundentries = true;

$id = @mysql_result($result, $i, 'id');
$title = @mysql_result($result, $i, 'title');
?>
<option value="<?= $id; ?>"><?= $title; ?></option>
<?

i++;
}
myclose;
?>

Gimlin
Jul 29th, 2002, 10:20 PM
<option value="<?= $id; ?>"><?= $title; ?></option>

whats with the "=$id" should just be $id, same for title

DJ P@CkMaN
Jul 30th, 2002, 12:07 AM
the <?= $id; ?> is just a short way of typing <?php echo $id; ?>

The Hobo
Jul 30th, 2002, 12:27 AM
Originally posted by DJ P@CkMaN
the <?= $id; ?> is just a short way of typing <?php echo $id; ?>

and also a very bad programming practice.

The Hobo
Jul 30th, 2002, 12:29 AM
Why don't you just do this?:


<?php

myconnect();


$query = "SELECT * FROM `songs` ORDER BY `id` DESC";
$result = mysql_query($query);
$rows = @mysql_num_rows($result);

$foundentries = false;

while ($i < $rows) {
$foundentries = true;

$id = @mysql_result($result, $i, 'id');
$title = @mysql_result($result, $i, 'title');

echo "<option value=\"$id\">$title</option>";

i++;
}
myclose;
?>

:confused:

phpman
Jul 30th, 2002, 09:49 AM
take the stupid ` off the column names and table

and you should never use @ to surpress the errors until you know it will work without getting an error. see you have an error and you use the @ so how do you know where the error is being generated from? nothing towards you hobo I am just stating this in general. :)


Carp: what line is 322? and try not to use mysql_result as it is a lot slower than mysql_fetch_array().

phpman
Jul 30th, 2002, 09:53 AM
<?php

myconnect();

$query = "SELECT * FROM songs ORDER BY id DESC";
$result = mysql_query($query);
echo "<form>";
while ($row = mysql_fetch_array($result)) {
$foundentries = true;

echo "<option value=\"".$row["id"]."\">$row["title"]</option>";

}
echo "</form>";
myclose();
?>

Gimlin
Jul 30th, 2002, 02:38 PM
Originally posted by DJ P@CkMaN
the <?= $id; ?> is just a short way of typing <?php echo $id; ?>

Learn something new everyday :)

cpradio
Jul 30th, 2002, 02:44 PM
Originally posted by phpman

<?php

myconnect();

$query = "SELECT * FROM songs ORDER BY id DESC";
$result = mysql_query($query);
echo "<form>";
while ($row = mysql_fetch_array($result)) {
$foundentries = true;

echo "<option value=\"".$row["id"]."\">$row["title"]</option>";

}
echo "</form>";
myclose();
?>



<?php

myconnect();

$query = "SELECT * FROM songs ORDER BY id DESC";
$result = mysql_query($query);
echo "<form>";
while ($row = mysql_fetch_array($result)) {
$foundentries = true;

echo "<option value=\"".$row["id"]."\">".$row["title"]."</option>";

}
echo "</form>";
myclose();
?>

The Hobo
Jul 30th, 2002, 04:53 PM
Originally posted by phpman
nothing towards you hobo I am just stating this in general. :)

I didn't put them in there, I just copied his code. In fact, I didn't even realize they were in there. :)

carp
Jul 31st, 2002, 10:43 AM
I fixed my error, All I had to do was put a $ before i++. I would have said this before but I couldn't connect to the server.

phpman
Jul 31st, 2002, 10:46 AM
but our way you don't need to add the i variable and is more proficient.