Reply to Re: [PHP] mysql query

Your name:

Reply:


Posted by Stephen Johnson on 02/18/05 03:05

Now I am assuming that 4 and 6 would not always be the next article ID -
otherwise you could just increment your id accordingly.

If you wanted to do that without running multiple queries, this is who I
might do it, rather sloppy, but I think it would work.

$idGet= $_GET['id'];
$sql = "select id, title from articles";
$db->query($sql);
$i=0;
while($db->getRow()) {
$id[$i] = $db->row['id'];
$title[$i] = $db->row['title'];
$i++;
if($id[$i] == $idGet) {
$j = $I;
}
}

$prev = $j-1;
$next = $j+1;

<<previous $title[$prev ]
next $title[$next] >>



<?php
/*

Stephen Johnson c|eh
The Lone Coder

http://www.thelonecoder.com
stephen@thelonecoder.com

562.924.4454 (office)
562.924.4075 (fax)

continuing the struggle against bad code

*/
?>

> From: "Sebastian" <sebastian@broadbandgaming.net>
> Date: Thu, 17 Feb 2005 19:24:50 -0500
> To: <php-general@lists.php.net>
> Subject: [PHP] mysql query
>
> Hello,
> im working on an article system and looking to avoid running three queries.
> example, i have this query:
>
> SELECT id,title FROM articles WHERE id=$_GET[id]
>
> now say $_GET[id] = 5
>
> I would like to get the previous id 4 and the next id 6 (if there is one)
> so i can do something like:
>
> << Previous Article [Title]
> Next Article [Ttitle] >>
>
> i would assume this is impossible without running mulitple queries? just
> thought i'd ask in case i am wrong. i am using mysql 4x
>
> thanks

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация