Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP/SQL Novice problem!
Old 05-13-2009, 11:19 AM PHP/SQL Novice problem!
Junior Talker

Posts: 2
Name: John
Trades: 0
discvHello, hope someone would be so kind as to help me?

Although I am the webmaster for my company I have no html/php training but I'm a fairly quick learner (With a little help from Google!).

I work for a magazine publisher and we have an extensive library of back issues that people are forever ringing up about with brilliant questions like:
"I appeared in your mag in 1978 or 79 can you find the issue and send me a copy?" ...Er, No!!!

So I decided to setup a database using Open Office that uses a MySQL database running on our Xserve to enter data.

Through various tutorials I have managed to create a webpage that displays all records in one great big table, now I want to create a webpage that allows the public to query the records and only display the relevant ones.

Here's what I've cobbled together so far:

PHP Code:
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM archive_table";
$result=mysql_query($query);

$num=mysql_numrows($result); 

mysql_close();

echo 
"<b><center>Database Output</center></b><br><br>";

?>
<left>
<table border="0" cellspacing="2" cellpadding="2">
<tr> 
<th><font face="Arial, Helvetica, sans-serif">Magazine</font></th>
<th><font face="Arial, Helvetica, sans-serif">Month</font></th>
<th><font face="Arial, Helvetica, sans-serif">Year</font></th>
<th><font face="Arial, Helvetica, sans-serif">Page No.</font></th>
<th><font face="Arial, Helvetica, sans-serif">Person/Subject</font></th>
<th><font face="Arial, Helvetica, sans-serif">Reg Col?</font></th>
<th><font face="Arial, Helvetica, sans-serif">Author</font></th>
<th><font face="Arial, Helvetica, sans-serif">Photo's?</font></th>
<th><font face="Arial, Helvetica, sans-serif">Colour?</font></th>
<th><font face="Arial, Helvetica, sans-serif">Cover?</font></th>
<th><font face="Arial, Helvetica, sans-serif">Comments</font></th>
</tr>

<?
$i
=0;
while (
$i $num) {
$Magazine=mysql_result($result,$i,"Magazine");
$Year=mysql_result($result,$i,"Year");
$Month=mysql_result($result,$i,"Month");
$Page_No=mysql_result($result,$i,"Page_No");
$Person_Subject=mysql_result($result,$i,"Person_Subject");
$Regular_Col=mysql_result($result,$i,"Regular_Col");
$Author=mysql_result($result,$i,"Author");
$Photographs=mysql_result($result,$i,"Photographs");
$Colour_Pics=mysql_result($result,$i,"Colour_Pics");
$Front_Cover=mysql_result($result,$i,"Front_Cover");
$Comments=mysql_result($result,$i,"Comments"); 
?>

<tr> 
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Magazine"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Month"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Year"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Page_No"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Person_Subject"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Regular_Col"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Author"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Photographs"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Colour_Pics"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Front_Cover"?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Comments"?></font></td>
</tr>
<?
++$i;

echo 
"</table>";

?>
I have tried to use a couple of tutorials to help me but I can't get anything to work.

What I would like is a search field that query's all records and displays results so if somebody wants to find any articles that featured "Bruce Lee" the result would look like:-

Code:
Month  Year  Page No   Person/Subject     Reg Col?  Author       Photo?  Colour?  Cover?
May    1980    36      Bruce Lee             Y      A. Smith       Y        Y         
April  2000    16      Bruce Lee                    Brian Jones    Y        Y       Y 
April  2002    3       Teaching Toddlers            Bruce Lee      Y        Y         
July   2003    34      History of Bruce Lee         Dave Hughes    Y        Y         
June   2008    36      Bruce Lee's Student   Y      Mr E. Nigma    Y        Y
Can anyone help?

Please!

Last edited by johnnydeee; 05-13-2009 at 11:48 AM.. Reason: Extra info!
johnnydeee is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-13-2009, 08:54 PM Re: PHP/SQL Novice problem!
Junior Talker

Posts: 1
Name: Larry
Trades: 0
If I am understanding you correctly you are storing this data in a mySQL database and want to be able to search through a particular column for fields that will match your search string?

Here is a quick example of a simple search form I've used in the past..

the search form
Code:
<form method="POST" action="search.php">
  <table border="0" cellspacing="2" align=left">
    <tr>
      <td valign=bottom><b>Search for</b></td>
      <td><input type="text" name="searchstring" size="35"> in</td>
      <td><input type="submit" value="Submit"></td>
     </tr>
  </table>
</form>
the SQL query you would run
Code:
$sql="SELECT * FROM mytable WHERE mycolumn LIKE '%$searchstring%'";
Hope that helps.
__________________
Larry Dougherty, Support Engineer,
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
ldougherty is offline
Reply With Quote
View Public Profile
 
Old 05-14-2009, 05:00 AM Re: PHP/SQL Novice problem!
Junior Talker

Posts: 2
Name: John
Trades: 0
Hi Larry,

Thanks for your reply, I want to be able to search all columns for the search string, from only one search query, if that makes any sense!
johnnydeee is offline
Reply With Quote
View Public Profile
 
Old 05-14-2009, 09:30 PM Re: PHP/SQL Novice problem!
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
This is an excellent online tutorial for you to use:
http://devzone.zend.com/node/view/id/1304
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP/SQL Novice problem!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43521 seconds with 12 queries