Jump to content
Sign in to follow this  
ricmcdonald

Help with php to display a list from a SQL Query

Recommended Posts

Hi There

I do not have enough php knowledge to achieve this simple task but I am guessing that someone here will be able to quickly help

 

I have a successful query that returns members names and  and a membership plan ID

 

The data base name is wapja908_joom389

 

SELECT CONCAT(  `first_name`," "  , `last_name`) AS name,`plan_id`as plan
 
FROM  `josgw_osmembership_subscribers` 
 
where  `plan_subscription_status` =1
ORDER BY  `plan_id`
 
I would like to be able to place this list into a web page, , the site is joomla based 
any help would be appreciated 

Share this post


Link to post
Share on other sites

no need to complicate things, use wildcard in your query like

"select * from table_name where condition='codition name' order by id"

Share this post


Link to post
Share on other sites

no need to complicate things, use wildcard in your query like

"select * from table_name where condition='codition name' order by id"

Share this post


Link to post
Share on other sites

yes that is simple  but that brings in all the fields in the table, I want to limit it to the name and plan id

Ant then I need the PHP to place it onto a page

Share this post


Link to post
Share on other sites

ok then do this

$query="select name, plan_id from table_name where condition='condition_name' order by id";

then execute the query with mysqli or pdo and create a loop and type the necessary html code like this

<table>
foreach($fetched_data as $content)
{
$result .="
<tr><td>".$content['name']."</td></tr>
<tr><td>".$content['plan_id']."</td></tr>

";
}
echo $result;

the above code will print it in table format, you can change it to any format and place it in your php page by either requiring or including the file or just run the loop in the same page.

 

to place the $result in the desired place at any page you have to create a separate php file and loop in it and then call it in the desired place like

require 'path to filename/filename.php';
or
include  'path to filename/filename.php';

hope this helps forgive my english it isn't my mother tongue.

Share this post


Link to post
Share on other sites

 

no need to complicate things, use wildcard in your query like

"select * from table_name where condition='codition name' order by id"

 

 

NO!, You always select the specific column names you want. DO NOT SELECT *

 

 

Modify this to use the results of your query

<!DOCTYPE html>
<html>
   <head>
      <title></title>
   </head>
   <body>
      <form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post">
         <select name="sort_by">
            <option value="">Select Option</option>
            <?php
               $array = array('id' => 'ID', 'name' => 'Name', 'amt' => 'Amount', 'status_filter' => 'Status');
               foreach ($array as $key => $value)
                   {
                   $selected = isset($_POST['sort_by']) && $_POST['sort_by'] == $key ? 'selected' : '';
                   echo "<option value='$key' $selected>$value</option>\n";
                   }
               ?>
         </select>
         <input name="submit" type="submit" value="Submit">
      </form>
   </body>
</html>
Edited by benanamen

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

×
×
  • 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.