Jump to content

multiple querys..to view by Columns in DB...


shane85

Recommended Posts

hey guys

 

question - right now on my page I have it set up to pull info from my db and display the info from my prospect_id column in DESC order. the code I am using is

 

$prospectEntries = mysql_query('SELECT * FROM prospects ORDER BY prospect_id DESC ' . $queryLimit) or trigger_error(mysql_error());

while ($prospectEntry = mysql_fetch_array($prospectEntries))
{
print_prospectEntry($prospectEntry);
}

 

At the top of my page, I have links:

 

View By:

Contact Next

Date Added

Company Name

City

 

now, I know I could achieve this by adjusting my query to view by date_added, company_name etc instead of prospect_id, However, how do I make it so I can have multiple querys in my code so that initially the page displays the way it currently is, by prospect_id, however if someone where to click the link "contact next" it would display by contact_next istead of prospect_id....same for the other links.

 

sorry for the newb quetson - thnx in advance

Link to comment
Share on other sites

page.php?orderby=prospect 

contact, date, company, city etc..

then your sql

switch($_GET['orderby'])
{
       case "contact": 
        $orderby="contact_next field"; 
      break; 
     
      case "date": 
     $orderby="date field"; 
     break; 
       
      case "company": 
       $orderby="company field"; 
       break; 

       case "city"; 
       $orderby="city field"; 
       break; 

       case default: 
        $orderby="prospect_id"; 
        break; 
       
}
$sql="select * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DWSC '.$queryLimit; 

Link to comment
Share on other sites

I commented out that line and adjusted the code to this but doesnt work...what is wrong???

 

switch($_GET['orderby'])
{
case "contact":
$orderby="$arrEntry[contact_next]";
break;
case "date":
$orderby="$arrEntry[tstamp]";
break;
case "company":
$orderby="$arrEntry[company_name]";
break;
case "city";
$orderby="$arrEntry[city]";
break;
//case default:
//$orderby="prospect_id";
//break;
}

// Prints all records from Prospect ID

//$prospectEntries = mysql_query('SELECT * FROM prospects ORDER BY prospect_id DESC ' . $queryLimit) or trigger_error(mysql_error());
$prospectEntries = mysql_query('SELECT * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DESC '.$queryLimit) or trigger_error(mysql_error());

Link to comment
Share on other sites

I commented out that line and adjusted the code to this but doesnt work...what is wrong???

 

switch($_GET['orderby'])
{
case "contact":
$orderby="$arrEntry[contact_next]";
break;
case "date":
$orderby="$arrEntry[tstamp]";
break;
case "company":
$orderby="$arrEntry[company_name]";
break;
case "city";
$orderby="$arrEntry[city]";
break;
//case default:
//$orderby="prospect_id";
//break;
}

// Prints all records from Prospect ID

//$prospectEntries = mysql_query('SELECT * FROM prospects ORDER BY prospect_id DESC ' . $queryLimit) or trigger_error(mysql_error());
$prospectEntries = mysql_query('SELECT * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DESC '.$queryLimit) or trigger_error(mysql_error());

 

Change the switch to:

switch($_GET['orderby'])
{
case "contact":
$orderby="$arrEntry[contact_next]";
break;
case "date":
$orderby="$arrEntry[tstamp]";
break;
case "company":
$orderby="$arrEntry[company_name]";
break;
case "city";
$orderby="$arrEntry[city]";
break;
default:
$orderby="prospect_id";
break;
}

Link to comment
Share on other sites

and you're mixing up your single and double quotes

$prospectEntries = mysql_query('SELECT * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DESC '.$queryLimit) or trigger_error(mysql_error());

should be

$prospectEntries = mysql_query("SELECT * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DESC ".$queryLimit) or trigger_error(mysql_error());

 

I commented out that line and adjusted the code to this but doesnt work...what is wrong???

 

switch($_GET['orderby'])
{
case "contact":
$orderby="$arrEntry[contact_next]";
break;
case "date":
$orderby="$arrEntry[tstamp]";
break;
case "company":
$orderby="$arrEntry[company_name]";
break;
case "city";
$orderby="$arrEntry[city]";
break;
//case default:
//$orderby="prospect_id";
//break;
}

// Prints all records from Prospect ID

//$prospectEntries = mysql_query('SELECT * FROM prospects ORDER BY prospect_id DESC ' . $queryLimit) or trigger_error(mysql_error());
$prospectEntries = mysql_query('SELECT * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DESC '.$queryLimit) or trigger_error(mysql_error());

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.