Jump to content

Help with php to display a list from a SQL Query


ricmcdonald
Go to solution Solved by benanamen,

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 
Link to comment
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.

Link to comment
Share on other sites

  • Solution

 

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