Closed Thread Icon

Topic awaiting preservation: PHP! ( what a suprise) Meets MYSQL (something new for Trig) (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12767" title="Pages that link to Topic awaiting preservation: PHP! ( what a suprise) Meets MYSQL (something new for Trig) (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP! ( what a suprise) Meets MYSQL (something new for Trig) <span class="small">(Page 1 of 1)</span>\

 
Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 05-30-2003 23:49

ok, after http://bmg.the-bronze.net the flatfile blog, I decided it was time to try something out with Mysql
and I had wbesite plans with some of the guys from hackingzone.org to put togther a newbie site to teach them about Linux and Networks and that sort of thing, unfortuantly I got lumbred with the job of site creation and the backend

and I got http://www.the-bronze.net/dhi/ as the design
and im working on the back atm,
unfortuanlty I cant get it to display data
the script shows 5 posts per page and then for every next 5 theres a new page thats assceiable va index.php?page=1,2,3,4,5,6

unfortuanlty it isnt outputting the news, ontop of that , I dont know how I would generate the links to index.php?page=1 and so along the bottom of my page,
my source is here http://www.the-bronze.net/dhi/index.txt
I hate to be a pain in the ass and I really appreciate the continual help you guys have given me whilst i've been learning php so yet agian as thankfully as I can be i'd realy appreciate any help whats so ever

Thanks
Trigger

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-31-2003 00:49

Umm er. okay


First if you want to access variables from the $_GET array, assign them their own variable and use that.

$page = $_GET['page'];

Don't muck with that array.

Second don't make the same query twice. $result = mysql_query("SELECT MAX(id) FROM news");
You don't really need to check if the input exceeds anything this way. If the select for stories retrieves nothing then so be it. They've gone to far.

Umm this is the heart of this page.

mysql_query("SELECT * FROM news ORDER BY 'id' DESC LIMIT $_GET[page],$offset",$connect);

Now the only things you need here is $page (remember don't use the $_GET array for this) and the $offset (page+5).

So start from there:

$page = $_GET['page'];
$offset = $page + 5;

now do your query
$result = mysql_query("SELECT * FROM news ORDER BY 'id' DESC LIMIT $page, $offset");

Now loop through that result

while ($row = mysql_array($result)) {
echo $row[0]. .... (whatever)
}

So to start with, this should be all you need

$page = $_GET['page'];
$offset = $page + 5;
$result = mysql_query("SELECT * FROM news ORDER BY 'id' DESC LIMIT $page, $offset");
while ($row = mysql_array($result)) {
echo $row[0] // All your display stuff here
}


Start with that and go from there




.:[ Never resist a perfect moment ]:.

Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 05-31-2003 00:53

And Regarding generatiogn the links?

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-31-2003 01:19


This should do it for next and last links. Not sure what exactly you want here.

<a href="<?= $PHP_SELF."?page=".$offset++; ?>">Next 5</a>
<a href="<?= $PHP_SELF."?page=".$offset-5; ?>">Last 5</a>

Oh another thing, don't do "Select * from..." that's a resource hog, name the fields you want to retrieve.




.:[ Never resist a perfect moment ]:.

Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 05-31-2003 01:39

WHat I was actulay thinking of, was

something like
Archive : 1, 2 ,3 ,4 ,5 ,6
being a link to each page each pae would display 5 messagesm but im too tire and intoixcated with alchol to figure out how to do that

Thanks
Trigger

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-31-2003 11:02

then you'd do a "select count(id) from ..."
to get the maximum number, divide that by 5 and print the links accordingly with a for loop.

oh, there was a tiny error in bitdamaged's code... should be $offset + 5, unless you want to go forward by 1, but backward by 5 news.

there's nothing wrong with using $_GET['page'] directly in the query, but you should make sure that it's a number with
is_numeric($_GET['page']) and otherwise set it to a default value, like 0.

(php can handle you setting the $_GET array just fine, I believe.)

so long,

Tyberius Prime

Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 05-31-2003 11:13

TP ok thanks for the help on the links

and as longas I check to see if its a number and stop things if its not that should stop any chance of sql injection attacks I take it ...

Thanks for yoru help

Trigger

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-31-2003 20:15

given it's the only variable you're sticking into your sql statment, yes.

Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 05-31-2003 21:05

ok, I got that problem sorted and then went on to do a edit post system and delete post system mysqls much better than flatfiles

Thanks for your help guys

Thanks
Trigger

« BackwardsOnwards »

Show Forum Drop Down Menu