Jump to content

Php news script - question probably concerning mysql


Recommended Posts

Hello, I've decided to make myself a very simple php script to write data into a DB and read it from there...

 

So, my question is.

How would I be able to make so that the page where the script is included to show only the newest 3 articles and puts the others on pages (1,2,3... etc) ?

Ideas would be appreciated.

A bit of scripting help would be really, really appreciated.

It's gonna be hard for anyone to give code when they don't know what you have.

 

Here's a method I use on my site for the main page.

I use a multiple mysql query and search/navigation using pagination. I don't know how you do your site at all.

 

$url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
$url .= "?".$query_string;
}
if ($url == "http://mysite.com/") { //can also add index.php or w/e you need with OR
$result = mysql_query("SELECT * FROM table ORDER BY ID DESC LIMIT 0,3");
} else {
$result = mysql_query("SELECT * FROM table ORDER BY ID DESC LIMIT 0,10");
}

 

If this doesn't help you and nobody else chimes in and walks you through I can help in a few days. I'll be too busy next few days.

I tried to break this down in another way and also try to explain it.

 

//this gets the current url
$url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
$url .= "?".$query_string;
}

//startrow would be used for any pagination you have to tell mysql where to start from
$startrow = 0;

//this sets the amount depending on what the url is
if ($url == "http://mysite.com/") { //can also add index.php or w/e you need with OR
$post_amount = 3;
} else {
$post_amount = 10;
}

//the partial mysql query
$result = mysql_query("SELECT * FROM table ORDER BY ID DESC LIMIT $startrow,$post_amount");

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.