I have my website pulling its content from a mysql database. Now on one of my pages that is being pulled from the database, specifically the index, I would like for more mysql queries to take place within that page to make it dynamically db driven as well.
Is this impossible? Do I have to put my queries on my templatepage.php that calls up the content and then just echo out what I need within the page. I'm running into quite a bit of trouble with it and no information will show up at all if i put all of the php/mysql querys into the db, but it will also not work if I put the queries outside, i just figured I may have been doing it wrong.
any suggestions or anything would help a bunch, thanks!
pulling page content from mysql db and executing querys
Moderator: General Moderators
-
fariquzeli
- Forum Contributor
- Posts: 144
- Joined: Mon Jun 24, 2002 9:16 am
- Location: Chicago
- Contact:
well..i have't worked with this much but i some times use eval(); to run php stored in db, give that a try.
here is more iinfo: http://www.php.net/manual/en/function.eval.php
here is more iinfo: http://www.php.net/manual/en/function.eval.php
-
fariquzeli
- Forum Contributor
- Posts: 144
- Joined: Mon Jun 24, 2002 9:16 am
- Location: Chicago
- Contact:
I read up on it, i'm not entirely sure I understand
If I want to echo out one of the variables from the query (which was inside the database) i would do something like this?:
$sql = "SELECT * FROM products WHERE id = '5' LIMIT 3";
$query = mysql_query($sql);
$result = mysql_fetch_assoc($query);
eval(echo $result['productName']
return();
or would i put the entire bit of codde in that??
If I want to echo out one of the variables from the query (which was inside the database) i would do something like this?:
$sql = "SELECT * FROM products WHERE id = '5' LIMIT 3";
$query = mysql_query($sql);
$result = mysql_fetch_assoc($query);
eval(echo $result['productName']
return();
or would i put the entire bit of codde in that??
-
JPlush76
- Forum Regular
- Posts: 819
- Joined: Thu Aug 01, 2002 5:42 pm
- Location: Los Angeles, CA
- Contact:
so basically what you want to do is have multiple queries on the same page?
here is a function that I use on all of my scripts:
that does my database connection...
now when I want to do queries I can do:
even though I have the same sql variable "RESULT" I can reuse it becauseI dont care about that SQL query anymore I just want my results and then I can assign the results to a variable.
here is a function that I use on all of my scripts:
Code: Select all
<?php
function dbconnect()
{
global $dbhost, $dbuname, $dbpass, $dbname;
mysql_connect($dbhost, $dbuname, $dbpass);
@mysql_select_db($dbname) or die ("Unable to select database");
}
//***** QUERY MYSQL RESULTS
function query_db($query)
{
dbconnect();
return @mysql_query($query);
}
?>now when I want to do queries I can do:
Code: Select all
<?php
// GET MOST REQESTED SHIPPING METHOD
$result = query_db("SELECT shipping_method,count(shipping_method) as ship FROM orders GROUP BY shipping_method ORDER BY ship desc LIMIT 1");
$row = mysql_fetch_array($result);
$shipmeth = ($row['shipping_method']);
$shipmeth = shipmethod($shipmeth);
$shipcount = ($row['ship']);
// GET POPULAR STATE
$result = query_db("SELECT cust_state,count(cust_state) as state FROM customers GROUP BY cust_state ORDER BY state desc LIMIT 1");
$row = mysql_fetch_array($result);
$state = ($row['cust_state']);
$statenum = ($row['state']);
?>-
fariquzeli
- Forum Contributor
- Posts: 144
- Joined: Mon Jun 24, 2002 9:16 am
- Location: Chicago
- Contact:
-
fariquzeli
- Forum Contributor
- Posts: 144
- Joined: Mon Jun 24, 2002 9:16 am
- Location: Chicago
- Contact: