Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Simple php question

Simple php question
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Oct 8, 2004, 07:43 AM
 
Hi,

I have a website setup nicely, but I want to add a random quote generator using php. I found some basic tutorials on php but I don't know how to add the php to my existing index.html file. If I just copy and paste the php into the html file, the php doesn't display. If I changed the extension to .php, the text displays, but all of my images and such are gone.

Can someone please help me with how to put some simple php into my index.html file.

TIA.
Ian
     
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
Oct 8, 2004, 07:46 AM
 
post your code maybe?
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Oct 8, 2004, 07:58 AM
 
Hi,

OK, I hope this isn't too much code. The little bit of PHP is about 1/2 down or so:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>IGG Software, LLC</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="IGG Software--Beautiful, intuitive, powerful..the way Mac applications should be. Creators of iWork, iBank and iPaste.">
<meta name="keywords" content="IGG Software, iWork, iBank, iPaste, project management, time, billing, invoicing, invoice, finance, management, money, clipboard, to do, ical, address book, computer, software, shareware, download, applications, utility, utilities, Mac, Mac OS, MacOS, OS X, OSX, Macintosh, iMac, iBook, PowerBook, Ian Gillespie">
<link href="styles/standard.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript" src="scripts/antiSpamMail.js"></script>
<link rel="shortcut icon" href="images/logo.ico" type="image/x-icon" />
</head>
<body text="#000000" link="#000000" vlink="#000000" alink="#000000">
<table border="0" align="center" cellpadding="0" cellspacing="0" class="main">
<tr align="right">
<td colspan="2" valign="top">

<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="105" valign="top"><table border="0" cellspacing="1" cellpadding="0" align="left">
<tr>
<td nowrap class="slogan"><a href="http://www.iggsoftware.com"><img src="images/logo_symbol.jpg" alt="IGG Software, LLC" align="top" border="0"></a></td>
<td valign="middle" align="center" nowrap class="slogan"> <a href="http://www.iggsoftware.com"><img src="images/igg_logo_text_new.jpg" alt="IGG Software, LLC" height="40" width="346" border="0"></a> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td><font color="#3a3fa1">Beautiful, intuitive, powerful...the way Mac applications should be.</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><table border="0" cellspacing="0" cellpadding="0" class="menu">
<tr>
<td class="left"></td>
<td class="selected"><a href="index.html">Home</a></td>
<td class="separator"></td>
<td><a href="about.html">About</a></td>
<td class="separator"></td>
<td><a href="iwork/index.html">iWork</a></td>
<td class="separator"></td>
<td><a href="ibank/index.html">iBank</a></td>
<td class="separator"></td>
<td><a href="ipaste/index.html">iPaste</a></td>
<td class="separator"></td>
<td><a href="contact.html">Contact</a></td>
<td class="separator"></td>
<td><a href="support.html">Support</a></td>
<td class="separator"></td>
<td width="70"></td>
</tr>
</table>
</td>
</tr>
</table>
<img src="images/blank.gif" alt="Blank" width="100" height="20"> <br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td width="100%" class="content">
<br>

<?
/* HERE IS MY PHP TEST CODE
start by creating an array of quotes. To add to the array, just type $quote[#]="text you want displayed";
Each time you add to the aray, increase the # by 1*/

$quote[0]="first random quote";
$quote[1]="another random quote";
$quote[2]="another quote goes here";
$quote[3]="and this can go on forever";

/* If you add to the array, change the last number (3) to the number of the last item in the array.
If you remove items from the array, lower the last number to the amount of items in the array...*/

$randnum=mt_rand(0,3);

// this last line displays the quotes randomly.
echo $quote[$randnum];
?>
<table class="newsbox" width="450" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th>The pipeline</th>
</tr>
<tr>
<td>
<ul>
<li>iWork 2.2 has reached the Final Candidate stage of development. Go to the <a href="/iwork/index.html">iWork page</a> to try it out.
<li>Try out <a href="ipaste/index.html">iPaste 1.1b</a>. New features include a clip set manager, floating palette and the coolest feature of all: associate clip sets with applications!
<li><a href="iwork/index.html">iWork 2.1.5</a> is now available.<br>
iWork is an intuitive time-billing and invoicing solution. iWork 2.1.5 delivers enhanced stability and many speed optimizations.
<li><a href="ibank/index.html">iBank 1.4.6</a> is out!<br>This is a minor update that offers a number of small bug fixes usability enhancements. A full description of changes is available <a href="http://www.macupdate.com/info.php/id/11612">he</a><a href="http://www.versiontracker.com/dyn/moreinfo/macosx/19359">re</a>.
<li>We have broken code on iBank 2.0. Among several other new features, we will be adding budgeting capabilities and improved printing. </ul>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<br>
</td>
</tr>
<!-- Footer -->
<tr>
<td width="50%" height="13" valign="top" class="footer">&copy; Copyright 2004 by IGG Software, LLC</td>
<td width="50%" align="right" valign="top" class="footer">Created by <a href="http://www.vividvisions.at/en/" target="_blank">VividVisions</a></td>
</tr>
<!-- Footer end -->
</table>
</body>
</html>
     
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
Oct 8, 2004, 08:38 AM
 
Can't see anything wrong with the code and, yes, use the .php extension.

Um, you are loading up the file to the correct directory when you change the extension?
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Oct 8, 2004, 09:42 AM
 
Ok, I got it to work. I had to change the extension by doing a "Get Info..." in the Finder, as opposed to just clicking and editing it.

Thanks again!
     
   
Thread Tools
Forum Links
Forum 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 On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:14 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2