homepage Welcome to WebmasterWorld Guest from 54.167.174.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP Newby Simple PHP Help to Pull mySQL
frankb3



 
Msg#: 4313579 posted 11:48 am on May 17, 2011 (gmt 0)

I'm a volunteer host of my high school's alumni association website. HTML pages for every class year, back to 1957. I just recently setup all class listing in a mySQL database connected locally to a Filemaker 11 front end.
I'm reading a couple books on PHP and am trying find relevant examples on how to pull the data and echo it to each class page, and update the home page with the latest listings.
Basic field structure including a photo, data is being parsed from WuFoo forms.

Can someone help point me in a good direction as far as PHP is concerned. The samples I'm finding seem to be based on a web form of some sort - but nothing so far that fits with what I'm trying to do. I'm deploying it a little differently so that I can still preview and manage the posts before hitting the site and keep my local database up to date.

Thanks,

Frank

 

rajivatre

5+ Year Member



 
Msg#: 4313579 posted 1:07 pm on May 17, 2011 (gmt 0)

Hi Frank,
I can help. PM me what exactly you want and I can give you whatever solution such as sample code etc.
Since you are working as a volunteer, there will not be charge from my side whatsoever.

Thanks
Rajiv

frankb3



 
Msg#: 4313579 posted 2:42 pm on May 17, 2011 (gmt 0)

Rajivatre,

Thanks. I'm wanting to pull fields from mySQL into a three column table on each html page, based on class year, and whether an alumni has passed away. Those are handled in a separate table on each class page. I also need to post the most recent updates on the main page in a column by class year, and then at the bottom, those who have passed away under a heading called "remembrance".

I will also need to apply my website CSS for the text styles and color.

The calculated fields are done locally in Filemaker and synced to mcSQL, so it's an easy task to pull data the way I want without too much trouble.

Any suggestions?

Thanks,

Frank

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4313579 posted 4:36 pm on May 17, 2011 (gmt 0)

Welcome aboard! So you've exported the Filemaker data to mySQL? Excellent. :-)

You don't want to "create pages" for each member, you want the pages to output dynamically from your PHP script. Basically pull the record(s) from mySQL with PHP, insert them in a template, and output to the browser.

First you need to get your mySQL to a web site. You'd do a mysql dump of your database which will give you a file with an .sql extension. (unless FileMaker has already created an .sql file for you.)

Now you go into your web site control panel and create the database, then locate/log in to phpMyAdmin. In phpMyAdmin, use the import function to import your data.

Now comes the steep learning curve. :-) You need to learn PHP to connect with the database and output the data. Here's a good start [w3schools.com]. If you've never done PHP, start from the top, but you will get to the "meat" of the project in the Database section.

You will also need the manual [php.net] and will frequently need to require the mySQL manual [dev.mysql.com].

A small hint: don't do in programming what can be done in mySQL statements - before answering "how would I do this?" first scour the mySQL manual to see if there's a way to do it in mySQL statements. A good example is the robust time and date functions in mySQL.

frankb3



 
Msg#: 4313579 posted 1:53 pm on May 18, 2011 (gmt 0)

rocknbil,

Thanks for the info. I've been reading a lot of these materials already, these have been added to the library! I found a pretty simple example that I'm trying on my table that partially works. However, when I introduce a "WHERE" command, the result is a mySQL error. Here is the PHP I'm using. Any pointers?

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM my table ORDER BY Deceased DESC WHERE Class Year='1977'");

echo "<table border='1'>
<tr>
<th>Class Year</th>
<th>First Name</th>
<th>Last Name</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Class Year'] . "</td>";
echo "<td>" . $row['First Name'] . "</td>";
echo "<td>" . $row['Last Name'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

Removing the "WHERE" will successfully echo my entire table. So I'm a little stumped.

Here is the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

jspeed

5+ Year Member



 
Msg#: 4313579 posted 3:09 pm on May 18, 2011 (gmt 0)

Try backticking the field name. It may not like that there is a space.

WHERE `Class Year`='1977'

jspeed

5+ Year Member



 
Msg#: 4313579 posted 3:19 pm on May 18, 2011 (gmt 0)

Actually, your WHERE may be in the wrong spot after looking at it:

$result = mysql_query("SELECT * FROM `my table` WHERE `Class Year`='1977' ORDER BY `Deceased` DESC");

frankb3



 
Msg#: 4313579 posted 3:35 pm on May 18, 2011 (gmt 0)

jspeed

You are correct. The switch in order fixed it. How do I add an additional WHERE condition?

jspeed

5+ Year Member



 
Msg#: 4313579 posted 3:59 pm on May 18, 2011 (gmt 0)

SELECT * FROM `my table` WHERE `Class Year`='1977' OR `Class Year`='1978' ORDER BY `Deceased` DESC

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4313579 posted 4:38 pm on May 18, 2011 (gmt 0)

Right, the reason why you need to backtick is the space in the table name, which is generally not a good idea but the backticks fix it.

A W.O.W. using or: form the habit of parenthesizing or's. look at this:

$query = "SELECT * FROM `my table` WHERE some_table_value=1 and `Class Year`='1977' OR `Class Year`='1978' ORDER BY `Deceased` DESC";

So if some_table_value=1 and class year = 1977, it will return true, which may be expected.

But . . . if **only** the class year is 1978, it will still return true even if some_table_value is **not** 1, when you expect it to bind it to some_table_value=1. "this and that (false) . . . or that (true) . . . "

Parenthesizing the or binds either of the "or" conditions to the "and".

$query = "SELECT * FROM `my table` WHERE some_table_value=1 and (`Class Year`='1977' OR `Class Year`='1978') ORDER BY `Deceased` DESC";

frankb3



 
Msg#: 4313579 posted 12:33 am on May 19, 2011 (gmt 0)

Now that I have it working, the CONCAT function seems to be the best method to string a couple of fields together and return it into one table column. However, being new to the Syntax, I'm not sure where that would be placed in my code. I would also like to place a carriage return between the two and code first field with STRONG text.
Any suggestions...or pointers. The multiple examples make sense, just not comfortable with putting everything together. I'm such a newbie! Thanks for your patience.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved