Jump to content

Recommended Posts

Hey Guys

 

After shrinking my website down considerably, i still have one more section i think can be shrunk further.

 

I have 5 pages, all call the same database and display it the same way. The only thing that changes is the the value of a specific column in the where clause. I'm pretty sure these 5 pages could actually be 1 page, but not quite sure how. I will show the main page so you understand my meaning better:

 

<div id="body_right">

<div id="content2">

 

<?php

include ('library/tabs.php');

 

if(@strcmp($session->username,$req_user) == 0 ||

  $session->isAdmin()) {

 

// Call beginning of paging file

$tbname = 'blablabla';

include ('library/paging1.php');

 

$sql  = "SELECT blablabla_step1.*, blablabla_step2.* 

        FROM blablabla_step1 LEFT JOIN blablabla_step2

ON blablabla_step1.al_uname = blablabla_step2.uname

WHERE blablabla_step1.status = 'Send Offers'

ORDER BY blablabla_step1.al_date Desc

$limit";

 

 

$result = mysql_query($sql) or die('Error, list album failed. ' . mysql_error());

 

if (mysql_num_rows($result) == 0) {

echo "No album yet";

} else {

$total=mysql_num_rows($result);

echo '<strong>' . $total . '</strong> result(s) found for the term: <strong>' . @$_POST['find'] . '</strong>';

 

echo '<table align="center" class="table_list">';

 

while ($row = mysql_fetch_assoc($result)) {

 

include('library/database/contactview.php');

}

echo '</table>';

 

 

}

// Call end of paging file

include ('library/paging2.php');

 

} else{

include ('library/not_logged_in.php');

}

?>

</div>

</div>

 

So the red highlighted where statement is the only thing that changes, here is another example of one of the others below:

 

WHERE blablabla_step1.status != 'Send Offers' AND blablabla_step1.status != 'Not Available' AND blablabla_step1.status != 'Fee Received' AND blablabla_step1.status != 'Awaiting Docs' AND blablabla_step1.status != 'Active'

 

Any ideas how to combine these five pages?

 

And can that where statement actually be written shorter as well? i have tried using ( ) but cannot quite figured it out.

Link to comment
https://forums.phpfreaks.com/topic/157929-make-5-pages-into-just-1/
Share on other sites

Simple - use URL parameters. The paremeter is used in the WHERE condition after it has been validated:

 

http://www.xyz.com/page.php?param=abc
http://www.xyz.com/page.php?param=def

<?php
// page.php
  $result = mysql_query("SELECT * FROM table WHERE field='".mysql_real_escape_string($_GET['param'])."'");
?>

Do what the OP said but plz dont put the $_GET variable directly into the sql :)

 

Take the content of the $_GET variable and then check if contains the information that You want and then put it in the sql.

 

Or even better just put some URL variable to determine what where statement to use for ex:

 

1 means "where bla = bla1"

2 means "where bla = bla2"

etc

 

So make a switch statement to determine which of the predefined sql to use.

 

This is only for your own safty. Putting URl variables or anykind of variables directly into the sql can result sql injections.

Hope I helped You ;)

 

P.S. I wrote this in a hurry so if u need more information please say so :)

 

 

Using a session is not possible in this case because you would never know the value to store in the session. That is why it is passed in the URL. Hence multiple parameters for 1 page. URL parameters are an essential part of web programming - used correctly and properly validated there are no issues.

For paging u need couple of things to keep in mind. Like number of all rows, rows presented on page. So when you execute the query set up a limit in the SQL. And transfer from 1 page to another the number of rows that needs to be displayed (if it is changable) and the last number of the last displayed row.

 

Also You can find some really nice paging script on the web. Just use google a bit ;)

 

have fun

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.