1

so basically I am trying to write a php script that can be uploaded to a server and be located somewhere on my site to click. Then when it's clicked, it runs the mysql query and displays the information needed....This is what I have so far.

--Connect.php--

$dbhost = 'localhost';
$dbuser = '******';
$dbpass = '******';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
        ('Error connecting to mysql');

$dbname = '*****';
mysql_select_db($dbname);

?>

--the mysql command I need to have the php file run is

SELECT jsfdName.baseData AS Name, 
jsfdAddr.baseData as Address, 
jsfdZip.baseData AS Zip,      
jsfdCity.baseData AS City, 
sfdCounty.baseData AS County, 
jsfdState.baseData AS State
FROM jos_sobipro_field_data AS jsfdName
JOIN jos_sobipro_field_data AS jsfdAddr USING( sid )
JOIN jos_sobipro_field_data AS jsfdZip USING(sid)
JOIN jos_sobipro_field_data AS jsfdCity USING(sid)
JOIN jos_sobipro_field_data AS jfsdCounty USING(sid)
JOIN jos_sobipro_field_data AS jfsdState USING(sid)
WHERE jsfdName.fid = 36 AND jsfdAddr.fid = 37 AND jsfdZip.fid=38 AND jsfdCity.fid = 39 
AND jsfdCounty.fid = 40 AND jsfdState.fid = 41 AND sid > 329

So how do I write the php script to run this file within my website?

Thanks

1
  • Are those values constant in your WHERE clause? Commented May 5, 2012 at 18:13

2 Answers 2

1

Store your query in a php variable $query='That String'

Then use this to execute it:

$res=mysql_query($qry);

Then to look through every result:

while($row=mysql_fetch_assoc($res)) {
    print $row['Name']; }

:)

Sign up to request clarification or add additional context in comments.

2 Comments

Can I do this inside of the connect.php file or should I make another file that just includes connect and then does this command?
You could include the "connect" stuff in a file and include it anywhere you'll be needing MySQL, however, you should try to only use mysql_connect and mysql_select_db one time per page. :)
0

I guess you are looking for something like this..

$dbhost = 'localhost';
$dbuser = '******';
$dbpass = '******';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
    ('Error connecting to mysql');

$dbname = '*****';
mysql_select_db($dbname);

$sql = "SELECT jsfdName.baseData AS Name, 
jsfdAddr.baseData as Address, 
jsfdZip.baseData AS Zip,      
jsfdCity.baseData AS City, 
sfdCounty.baseData AS County, 
jsfdState.baseData AS State
FROM jos_sobipro_field_data AS jsfdName
JOIN jos_sobipro_field_data AS jsfdAddr USING( sid )
JOIN jos_sobipro_field_data AS jsfdZip USING(sid)
JOIN jos_sobipro_field_data AS jsfdCity USING(sid)
JOIN jos_sobipro_field_data AS jfsdCounty USING(sid)
JOIN jos_sobipro_field_data AS jfsdState USING(sid)
WHERE jsfdName.fid = 36 AND jsfdAddr.fid = 37 AND jsfdZip.fid=38 AND jsfdCity.fid = 39 
AND jsfdCounty.fid = 40 AND jsfdState.fid = 41 AND sid > 329
";

$result = mysql_query($sql);

if (!$result) {

echo "An error occurred in processing your    submission."; 
}   
$row=mysql_fetch_array($result);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.