This is a newbies forum, correct?
I have several pages of php that I created about 4-5 years ago for a client.
The client previously connected to about 5 tables in mysql.
Now I'm tasked with "just changing the mysql connection to the API we created".
So they want to maintain populating the exact same look and feel but posted via an API.
The client created the API I have a nondisclosure to deal with so I can't post it.
After lots of trial and error, I was able to call the data into a webpage with the code below, but now I'm now at a point where I have to really look at all of the fields and formatting that I did several years ago.
1.) Please look at my new code (of which I should source but can't find it). Should I be thinking about it in a different way? Maybe I should call the api data and have it post into a table in mysql (or is that even possible)?
2.) Can anybody provide me with tips or tricks as it relates to keeping the reformatting of my php code to a minimum?
NEW CODE (works right now, but it might be the wrong approach.. also, I didn't want to edit the php.ini file):
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.clientserver.com/api/nameofapi?primaryfieldname=desiredvalue");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
$result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://www.clientserver.com/api/nameofapi?primaryfieldname=desiredvalue/$2$3', $result);
echo $result
?>
ONE OF THE EASIER PAGES OF OLD PHP CODE (didn't include a bunch of html table formatting):
<?php
$username = "uname";
$password = "pwd";
$hostname = "hostname";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("dbname",$dbhandle)
or die("Could not select dbname");
$query = mysql_query("SELECT* FROM tblA ORDER BY field1");
while ($row = @mysql_fetch_array($query))
{
$variable1=$row["field2"];
$variable2=$row["field 3"];
echo "<tr bgcolor=\"#dddddd\"><td><center>";
echo $row["field1"];
echo ($variable2 != '') ? "<a href=\"$variable2\"></br>variable2fieldname</a>" : '';
echo "</center></td><td><center>";
echo $row["field4"];
echo "</center></td><td><center><span class=\"style2\">";
echo $row["field5"];
echo "</center></td><td><center>";
echo $row["field6"];
echo "</center></td><td><center>";
echo ($variable1 != '') ? "<a href=\"mailto:$variable1\">Email</a>" : '';
echo ltrim($row[""], '0');
}?>