Jump to content

use their own id


ecabrera

Recommended Posts

is it possible to use the while out side the php for ex.

 

<?php

 

require "scripts/connect.php";

 

$query = mysql_query("SELECT * FROM news WHERE section='gtkphp'");

while($rows = mysql_fetch_assoc($query)){

 

$id = $rows['id'];

$title = $rows['title'];

$body = $rows['body'];

}

mysql_close();

?>

 

make eache like have its own id number

 

<a href="view.php?='<?php echo $id;?>"></a>

<a href="view.php?='<?php echo $id;?>"></a>

<a href="view.php?='<?php echo $id;?>"></a>

Link to comment
Share on other sites

say i want them to be should inside a table how would i do that so the table dose not multiple

 

<table>

<tr>

<td>

<a href="view.php?='<?php echo $id;?>"></a>

<a href="view.php?='<?php echo $id;?>"></a>

<a href="view.php?='<?php echo $id;?>"></a>

</td>

</tr>

</table>

Link to comment
Share on other sites

<table>
<?php while($rows = mysql_fetch_assoc($query)) {?>
<tr>
<td>
<a href="view.php?='<?php echo $id;?>"></a>
<a href="view.php?='<?php echo $title;?>"></a>
<a href="view.php?='<?php echo $body;?>"></a>
</td>
</tr>
<?php } ?>
</table>

Link to comment
Share on other sites

nope

 

<?php

require "scripts/connect.php";

$query = mysql_query("SELECT * FROM news WHERE section='gtkphp'");


$id = $rows['id'];
$title = $rows['title'];
$body = $rows['body'];

?>

<table>
<?php while($rows = mysql_fetch_assoc($query)) {?>
<tr>
<td>
<a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a>
<a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a>
</td>
</tr>
<?php } ?>
</table>

Link to comment
Share on other sites

does not work

 

i have this

 

<?php

require "scripts/connect.php";


$query = mysql_query("SELECT * FROM news WHERE section='gtkphp'");
while($rows = mysql_fetch_assoc($query)) {

$id = $rows['id'];
$title = $rows['title'];
$body = $rows['body'];

}
?>

<table>
<?php while($rows = mysql_fetch_assoc($query)) {?>
<tr>
<td>
<a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a>
</td>
</tr>
<?php } ?>
</table>

Link to comment
Share on other sites

Look at your logic.

 

<?php

require "scripts/connect.php";


$query = mysql_query("SELECT * FROM news WHERE section='gtkphp'");
<table>
<?php while($rows = mysql_fetch_assoc($query)) {
$id = $rows['id'];
$title = $rows['title'];
$body = $rows['body'];
?>
<tr>
<td>
<a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a>
</td>
</tr>
<?php } ?>
</table>

Link to comment
Share on other sites

A few simple errors. I was missing a closing php tag.

 

Are you even trying to do this yourself?

 

<?php
require "scripts/connect.php";
$query = mysql_query("SELECT * FROM news WHERE section='gtkphp'");
?>
<table>
<?php while($rows = mysql_fetch_assoc($query)) {
$id = $rows['id'];
$title = $rows['title'];
$body = $rows['body'];
?>
<tr>
<td>
<a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a>
</td>
</tr>
<?php } ?>
</table>

Link to comment
Share on other sites

This may seem off topic, but why don't people look at the code given and try it for themselves?

It really irates me when people expect the code you post to work exactly as they want it, and then when it doesn't they don't even try to fix it.

 

Simply looking at the code highlighting would should you that the ending PHP tag was missing, or am I just nit picking here?

 

Regards, PaulRyan.

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.