This topic is locked

Complicated Question: Using custom code from advanced search

12/4/2007 11:14:35 AM
PHPRunner General questions
M
MarcusinMD author

Hello again,
I have worked my way through our entire interface with this program and it works pretty well. Looks like it will be on the purchase list in a few days.
The question I have is a bit complicated (for me at least with my limited php and mysql knowledge)
The data that is collected from the interface we created with this program needs to be used to generate map points (using yahoo maps). I have the data generated from this softwares interface and I can access it perfectly with the code snippet below but only with fixed settings that I choose. I want to be able to use the phprunner's interface search engine query results to generate the data used to create the map points.

<?php
function format_date($datetime) {



#match day/month/year hour:minute:seconds

preg_match("/(\d+)\/(\d+)\/(\d+)/",$datetime,$match);
#reformat date string

$date = "$match[3]/$match[2]/$match[1]";



return $date;

}
echo <<<EOB

<html>

<head>

<script type="text/javascript"

src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=**************************************--">;

</script>

<style type="text/css">

#mapContainer {

height: 600px;

width: 800px;

}

</style>

</head>

<body>

<div align=center>

</script>

<div id="mapContainer"></div>
<script type="text/javascript">

// Create a lat/lon object

var myPoint = new YGeoPoint(39.5756050,-76.9816802);

//var myTitle = new YAnnotation("Easternuswx.com Snowfall Plotter","","");
// Create a map object

var map = new YMap(document.getElementById('mapContainer'),YAHOO_MAP_SAT);

// Add a pan control

map.addPanControl();

// Add a slider zoom control

map.addZoomLong();

// Display the map centered on a latitude and longitude

map.drawZoomAndCenter(myPoint, 11);

map.addTypeControl();
function createYahooMarker(geopoint, num, member, ballon) {

var myImage = new YImage();

myImage.src = 'http://www.easternuswx.com/snowplotter07/snowflake_icon3.gif';;

//myImage.size = new YSize(30,20);

myImage.size = new YSize(30,20);

myImage.offsetSmartWindow = new YCoordPoint(0,0);

var marker = new YMarker(geopoint,myImage);

//var swtext = "Marker <b> " + num + "</b>";

var swtext = ballon;

var label= member;

marker.addLabel(label);

YEvent.Capture(marker,EventsList.MouseClick,

function() { marker.openSmartWindow(swtext) });

return marker;

}
var i = 0;
var bounds = map.getBoundsLatLon();

var height = bounds.LatMax - bounds.LatMin;

var width = bounds.LonMax - bounds.LonMin;
EOB;
// Setup the database

$hostname = "localhost"; // database host

$username = ""; // database username

$password = ""; // database username's password

$db_name = ""; // database name

$admin_email = ""; // contact email to display on connection errors
// Connect to server

$linkID = @mysql_connect($hostname, $username, $password) or die("MySQL <strong>server</strong> connection failed; please advise ".$admin_email);
// Connect to database

@mysql_select_db($db_name, $linkID) or die("MySQL <strong>database</strong> connection failed; please advise ".$admin_email);
$gstrSQL = "select `_snowstorms`.`ID`, `_snowstorms`.`comments`, `_snowstorms`.`snowstorm_date`, `_snowstorms`.`snowstorm_total`, `_snowstorms`.`precip_type`, `_snowstorms`.`ID1`, `_members`.`login_name`, `_members`.`city`, `_members`.`state`, `_members`.`longitude`, `_members`.`latitude` From `_snowstorms` inner join `_members` on `_snowstorms`.`ID` = `_members`.`ID` where `_snowstorms`.`snowstorm_date` = '2007-12-02'";
$query = sprintf($gstrSQL);
$resultID = @mysql_query($query);

$row_count = 0;

for ($i = 0; $i < mysql_num_rows($resultID); $i++)

{

$row = mysql_fetch_assoc($resultID);

if (!empty($row[longitude]))

{

$lon = $row[longitude];

$lat = $row[latitude];

$member = $row[login_name];

$snowtotal = $row[snowstorm_total];

$comments = $row[comments];

$snowdate = $row[snowstorm_date];

// $snowdate = $snowdate->format("m-d-Y");

$ballon_text = $snowdate."<BR>".$member."<BR>";//$comments;





echo <<<EOB
var GeoPoint = new YGeoPoint($lat,$lon);

var marker = createYahooMarker(GeoPoint,$i,'$snowtotal','$ballon_text');

map.addOverlay(marker);
EOB;
// echo $longitude[$i];

// echo "<br>";

// Increment non-empty row counter

$row_count++;

}

}

// Free the memory used by the query result

mysql_free_result($resultID);

// Close database connection

mysql_close($linkID);
echo <<<EOB

</script>
</DIV ALIGN>

</body>

</html>

EOB;

?>


To get started I edited the already generated php code from a custom list page created by phprunner. AT the end of the "...list.php" file I added the above code removing all of the database connection code (because phprunner already handles that for me)
I am hoping that I can just drop the correct variable into the fields below and be on my way but I cannot figure out what this should be:
This is how I query the database:
$gstrSQL = "select `_snowstorms`.`ID`, `_snowstorms`.`comments`, `_snowstorms`.`snowstorm_date`, `_snowstorms`.`snowstorm_total`, `_snowstorms`.`precip_type`, `_snowstorms`.`ID1`, `_members`.`login_name`, `_members`.`city`, `_members`.`state`, `_members`.`longitude`, `_members`.`latitude` From `_snowstorms` inner join `_members` on `_snowstorms`.`ID` = `_members`.`ID` where `_snowstorms`.`snowstorm_date` = '2007-12-02'";
$query = sprintf($gstrSQL);
$resultID = @mysql_query($query);

$row_count = 0;

for ($i = 0; $i < mysql_num_rows($resultID); $i++)
The bolded areas are what I do not know and need to get the correct variable name (the one generated by phprunner) or what are the variables that phprunner uses for $query = sprintf($gstrSQL); so that I can use it in my code above.
I hope this is enough info, I have searched for about an hour through all the posts but cannot seem to find anything that may pertain to this.
Thank You!

Sergey Kornilov admin 12/4/2007

Sorry, I don't get it.
What exactly you need to get from PHPRunner? Search SQL query? Selected search variables?

M
MarcusinMD author 12/4/2007

I need to have access to every value in the database and be able to loop through each one so that I can plot points on the yahoo map.
upfront: I know how to get the data into the yahoo map to make it work.
What this needs to do is the following:
Read 1 record at a time based on the search criteria used in either advanced search or the search bar at the top of a custom list page.
Once each record is read it will have to be placed into a variable so that it can be passed to the yahoo map function:

$resultID = @mysql_query($query);

$row_count = 0;

for ($i = 0; $i < mysql_num_rows($resultID); $i++)

{

$row = mysql_fetch_assoc($resultID);

if (!empty($row[longitude]))

{

$lon = $row[longitude];

$lat = $row[latitude];

$member = $row[login_name];

$snowtotal = $row[snowstorm_total];

$comments = $row[comments];

$snowdate = $row[snowstorm_date];

// $snowdate = $snowdate->format("m-d-Y");

$ballon_text = $snowdate."<BR>".$member."<BR>";//$comments;

echo <<<EOB
var GeoPoint = new YGeoPoint($lat,$lon);

var marker = [b]createYahooMarker(GeoPoint,$i,'$snowtotal','$ballon_text');[/b]

map.addOverlay(marker);


The above bolded function contains variables that are collected via a query to the database that contains the values needed for plotting the data which is longitude, latitude and a snowfall total (among other things)
My problem is while I can do this as a seperate php file like "generatemap.php" using my own mysql opendb commands and query, I need to be able to use the query that is generated by the phprunner software.

M
MarcusinMD author 12/4/2007

I need to have access to every value in the database and be able to loop through each one so that I can plot points on the yahoo map.
upfront: I know how to get the data into the yahoo map to make it work. I may even be able to insert my code into a custom php script added to the list view editor. (testing this with just a map works great, I just need to get access to the data so that I can add it to the map)
What this needs to do is the following:
Read 1 record at a time based on the search criteria used in either advanced search or the search bar at the top of a custom list page.
Once each record is read it will have to be placed into a variable so that it can be passed to the yahoo map function:

$resultID = @mysql_query($query);

$row_count = 0;

for ($i = 0; $i < mysql_num_rows($resultID); $i++)

{

$row = mysql_fetch_assoc($resultID);

if (!empty($row[longitude]))

{

$lon = $row[longitude];

$lat = $row[latitude];

$member = $row[login_name];

$snowtotal = $row[snowstorm_total];

$comments = $row[comments];

$snowdate = $row[snowstorm_date];

// $snowdate = $snowdate->format("m-d-Y");

$ballon_text = $snowdate."<BR>".$member."<BR>";//$comments;

echo <<<EOB
var GeoPoint = new YGeoPoint($lat,$lon);

var marker = [b]createYahooMarker(GeoPoint,$i,'$snowtotal','$ballon_text');[/b]

map.addOverlay(marker);


The above bolded function contains variables that are collected via a query to the database that contains the values needed for plotting the data which is longitude, latitude and a snowfall total (among other things)
My problem is while I can do this as a seperate php file like "generatemap.php" using my own mysql opendb commands and query, I need to be able to use the query that is generated by the phprunner software.

M
MarcusinMD author 12/4/2007

OK, maybe this will make a bit more clear (as mud right <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=23867&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> )
If I want to insert my code into a custom event on a list page
How do I access the following data from my database:
mysql_num_rows($resultID);
$row = mysql_fetch_assoc($resultID);
$lon = $row[longitude];

$lat = $row[latitude];

$member = $row[login_name];

$snowtotal = $row[snowstorm_total];

$comments = $row[comments];

$snowdate = $row[snowstorm_date];
If I know how to access this data from within the custom event I think I can achieve what I am looking for. I simply do not know how to access it because I don't know what variables hold them.

J
Jane 12/5/2007

Hi,
you can select required values from database in the custom event:

[/quote]

global $conn;

$rs = db_query("select * from TableName",$conn);

$dara = db_fetch_array($rs);

//$data["FieldName"] - FieldName value

[/quote]

or use one of the predefined event on the Events tab.
More info about events and parameters is in the PHPRunner help.