beam1985 Posted March 9, 2008 Share Posted March 9, 2008 My teacher just told me for my project that i need to use a class. I have no idea what a class in php is or how to utilize or implement one. can anyone paraphrase these instructions please? i have no idea what it means. remember that we've been building everything as a class called ReadWriteWeb: class ReadWriteWeb { //methods and properties here var $variable = array(); function aMethod() { } } $mc = new ReadWriteWeb(); $mc->aMethod(); so, create new classes & use those instead of interleaving your php with your html as you are now. Link to comment https://forums.phpfreaks.com/topic/95281-using-php-via-a-class/ Share on other sites More sharing options...
Barand Posted March 9, 2008 Share Posted March 9, 2008 does this help (or confuse even more) ? http://www.phpfreaks.com/forums/index.php/topic,104878.msg418672.html#msg418672 Link to comment https://forums.phpfreaks.com/topic/95281-using-php-via-a-class/#findComment-487999 Share on other sites More sharing options...
beam1985 Posted March 9, 2008 Author Share Posted March 9, 2008 does this help (or confuse even more) ? http://www.phpfreaks.com/forums/index.php/topic,104878.msg418672.html#msg418672 hah i wouldnt say it was any more confusing, since im 100% confused already, but how would i work that into these already finished codes? <?php mysql_connect('localhost', 'user', 'pass'); mysql_select_db('ragra'); $query = sprintf("SELECT * FROM article ORDER BY id DESC"); $result = mysql_query($query); echo "<table>"; echo "<tr>"; echo "<td>"; echo "<img src='comcarblog.jpg'>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "<table>"; echo "<tr>"; echo "<td><a href='main.php' alt='Home'><img src='home.jpg'></a>"; echo "</td>"; echo "<td><a href='' alt=''><img src='blank.jpg'></a>"; echo "</td>"; echo "<td><a href='add.php' alt='Admin'><img src='admin.jpg'></a>"; echo "</td>"; echo "</tr>"; echo "</table>"; if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } while ($row = mysql_fetch_assoc($result)) { echo "<br>"; echo "<table border='1px' width='505px' bgcolor='#bdbdbd'>"; echo "<tr>"; echo "<td>"; echo "<font face='arial,helvetica' size='8px' color='#41a1f3'>{$row['title']}</font>"; echo "<br>"; echo "<font halign='right' face='arial,helvetica' size='4px' color='#f3d841'>{$row['tagline']}</font>"; echo "<br>"; echo "<font face='arial,helvetica' size='5px' color='#617fa0'>{$row['content']}</font>"; echo "<br>"; echo "<font face='arial,helvetica' size='4px' color='#f3d841'>Author: {$row['author']}</font>"; echo "<br>"; echo "<font face='arial,helvetica' size='4px' color='#41a1f3'>Date Posted: {$row['date']}</font>"; echo "<br>"; echo "<font face='arial,helvetica' size='4px' color='#41a1f3'>Category: {$row['category']}</font>"; echo "</td>"; echo "</tr>"; echo "</table>"; } mysql_free_result($result); ?> <?php $host="localhost"; // Host name $username="user"; // Mysql username $password="pass"; // Mysql password mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("ragra"); if (!isset($_POST['delete'])){ $sql = "SELECT * FROM article"; $result = mysql_query($sql); $count = mysql_num_rows($result); ?> <table><tr><td><img src="comcarblog.jpg"></td></tr></table> <table><tr><td><a href="main.php" alt="Home"><img src="home.jpg"></a></td> <td><a href="" alt=""><img src="blank.jpg"></a></td> <td><a href="add.php" alt="Admin"><img src="admin.jpg"></a></td> </tr></table><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr><td colspan="4" bgcolor="#41a1f3"><form name="form1" method="post">You're about to delete some posts!</td></tr></table> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr><td align="center" bgcolor="#f3d841">Number</td> <td align="center" bgcolor="#f3d841">Id</td> <td align="center" bgcolor="#f3d841">Title</td> <td align="center" bgcolor="#f3d841">Tagline</td> <td align="center" bgcolor="#f3d841">Author</td></tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr><td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="checkbox[]" value=" <?php $rows['id'] ?>"> </td><td bgcolor="#FFFFFF"> <?php echo $rows['id']; ?></td><td bgcolor="#FFFFFF"> <?php echo $rows['title']; ?> </td> <td bgcolor="#FFFFFF"> <?php echo $rows['tagline']; ?> </td><td bgcolor="#FFFFFF"> <?php echo $rows['author']; ?> </td></tr> <input type="hidden" NAME="cbnbr[]" VALUE="cbnbr"> <?php } ?> <tr><div><td colspan="5" align="center" bgcolor="#FFFFFF"> <input name="delete" type="submit" id="delete" value="Delete"></td></div></tr></table> <?php } else{ if($_POST['delete'] == 'Delete'){ for($i=0;$i<count($_POST['checkbox']);$i++){ $del_id = $_POST['checkbox'][$i]; $sql = "DELETE FROM article WHERE id='$del_id'"; $result = mysql_query($sql); } header("Location:delete.php"); } } mysql_close(); ?> <?php if(isset($_POST['submit'])) { mysql_connect('localhost', 'user', 'pass'); mysql_select_db('ragra'); $title = $_POST['title']; $tagline = $_POST['tagline']; $content = $_POST['content']; $author = $_POST['author']; $category = $_POST['category']; $result=MYSQL_QUERY("INSERT INTO article VALUES (NULL, '$title', '$tagline', '$content', now( ) , '$author', '$category')" ); echo "<table> <tr><td><img src='comcarblog.jpg'></td></tr> </table> <table> <tr> <td><a href='main.php' alt='Home'><img src='home.jpg'></a> </td> <td><a href='' alt=''><img src='blank.jpg'></a> </td> <td><a href='add.php' alt='Admin'><img src='admin.jpg'></a> </td> </tr> </table> <table> <tr> <td> <p><font face='arial,helvetica' size='6px' color='#41a1f3'>You have Sucsesfully added a post!</font></p> <p><font face='arial,helvetica' size='6px' color='#617fa0'><a href='main.php' alt=''>View your post on the mainpage here</a></font></p> </td> </tr> </table>" } else { echo "<form method='post' action='add.php'> "; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<img src='comcarblog.jpg'>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "<table>"; echo "<tr>"; echo "<td><a href='main.php' alt='Home'><img src='home.jpg'></a>"; echo "</td>"; echo "<td><a href='' alt=''><img src='blank.jpg'></a>"; echo "</td>"; echo "<td><a href='add.php' alt='Admin'><img src='admin.jpg'></a>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "<table>"; echo "<TR> "; echo "<TD><font face='arial,helvetica' size='4px' color='#41a1f3'>Title:</font></TD> "; echo "<TD>"; echo "<INPUT TYPE='TEXT' NAME='title' VALUE='Whats the title' size=60>"; echo "</TD>"; echo "</TR>"; echo "<br>"; echo "<TR> "; echo "<TD><font face='arial,helvetica' size='4px' color='#617fa0'>Tagline:</font></TD> "; echo "<TD>"; echo "<INPUT TYPE='TEXT' NAME='tagline' VALUE='write something witty' size=60>"; echo "</TD>"; echo "</TR>"; echo "<br> "; echo "<TR> "; echo "<TD valign='top'><font face='arial,helvetica' size='4px' color='#617fa0'>Content:</font></TD> "; echo "<TD>"; echo "<TEXTAREA NAME='content' ROWS='15' COLS='45'>This better be good!</TEXTAREA>"; echo "</TD>"; echo "</TR>"; echo "<br>"; echo "<TR> "; echo "<TD><font face='arial,helvetica' size='4px' color='#617fa0'>Author:</font></TD> "; echo "<TD> "; echo "<SELECT NAME='author'> "; echo "<OPTION VALUE='Bob'>Bob "; echo "<OPTION VALUE='Walker'>Walker"; echo "<OPTION VALUE='Somebody Else'>Somebody Else "; echo "</SELECT> "; echo "</TD>"; echo "</TR>"; echo "<br> "; echo "<TR> "; echo "<TD><font face='arial,helvetica' size='4px' color='#617fa0'>Category:</font></TD> "; echo "<TD>"; echo "<INPUT TYPE='TEXT' NAME='category' VALUE='whats the category' size=60>"; echo "</TD>"; echo "</TR>"; echo "<br>"; echo "<TD>"; echo "<INPUT TYPE='submit' name='submit' value='submit'>"; echo "</TD> "; echo "</TR>"; echo "</table>"; echo "</form>"; } ?> Link to comment https://forums.phpfreaks.com/topic/95281-using-php-via-a-class/#findComment-488005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.