Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Functions take parameters. The parameters allow a function to know what it is supposed to do. Most functions return a value. In the case of the date() function, it returns a formatted string of a given date. To be able to return this date, it needs to know two things. Firstly, it needs to know what format it should return the date in. Second, it needs to know what date and time it is returning a format for. Its first parameter, format, is the format of the returned value. This parameter is a string - as was said, a string is a 'line of characters' if you will. In this particular case, the string is composed of specific letters, which tell the function what format it is. For example, the character 'd' is used to display the day of the month (full list of chracters here. The second parameter is the date and time that we are returning a function for. The reason why it is optional is the function can assume that we want to use the current date and time. So, if we dont pass a value for the second parameter, the function returns a formatted string representing the current date and time. However, if we do pass a value, it must be an integer (thats what the int represents in the above function prototype(thats whats this thing - string date (string format [, int timestamp]) - is called)). That integer is the number of seconds passed since the unix epoch (1st january 1970). Hopefully that clears some of that up.
  2. I assume this line: echo '<a href="Cart.php?action=delete&id='.$_GET['id'].'">'."Remove?".'</a>'; should read: echo '<a href="Cart.php?action=delete&id='.$row['id'].'">'."Remove?".'</a>'; At the moment, all the links contain the same ID - the one in $_GET['id'].
  3. Never done it, but i expect you could zip the contents of the file and let the user download that.
  4. See this topic: http://www.phpfreaks.com/forums/index.php/topic,168930.0.html Either modify your DateSelector function so that it does not echo the data, but returns a string (best option) or use output buffering (explained in the reply to the above thread)
  5. Well, it doesn't have to be called functions.php.
  6. Can't you just rewrite the ssi_recentTopics() function so that it doesn't echo data, but returns a string? If thats not possible, then you might be able to use output buffering. You'll need to place ob_start() at the top of your script. You'll then need to flush the contents of the buffer (what has been output to the screen), before calling the ssi_recentTopics() function (this enables any other output to be unaffected), call the ssi_recentTopics() function, then use ob_get_clean() to get the new contents of the buffer (what is echoed in ssi_recentTopics() ) , and place it inside your string. <?php ob_start();//placed at the TOP of your script //the rest of your script function home(){ ob_flush();//flush current contents of buffer - any other content would be sent now. ssi_recentTopics();//call the function $con = '<span class="main-text">Well well well,.. it would seem you have found your way to the brotherhood of {WRL}. More then a simple gaming clan, we are what you would call a movement. Honor, respect & duty,.. these are words we take seriously. Honor your clan, respect to all, & and your duty to your clan.<br /> <br /> Here rank matters very little, and although we do strive to be the best we can be. Your loyality to our cause is of the greatest importance. You will come to find that we are not the typical gaming clan. We do not promote for skills or even consider it that important. We do not attack other clans of players with any evil intent. Although we do plan and host many wars, these are for fun or competition only.<br /> <br /> Also we support many games and are constanly expanding. Our forums are very active and our site recieves over 1 million hits a month. So welcome to the brotherhood,.. follow the rules, treat people with respect and reserve your spot in history with the {WRL} movement. Make sure that you read the rules section and such</span><br /> <br /> <br /><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="2%" class="head_repeat"><img src="images/mid-left-head.gif" width="9" height="25" /></td> <td width="96%" class="head_repeat style7">Recent Post</td> <td width="2%" class="head_repeat"><div align="right"><img src="images/mid-right-head.gif" width="9" height="25" /></div></td> </tr> <tr> <td height="13" colspan="3" bgcolor="#CECFCE" class="menu-bor">' . ob_get_clean() . '</td> </tr> </table> <br /> <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="2%" class="head_repeat"><img src="images/mid-left-head.gif" width="9" height="25" /></td> <td width="96%" class="head_repeat style7">Gaming News </td> <td width="2%" class="head_repeat"><div align="right"><img src="images/mid-right-head.gif" width="9" height="25" /></div></td> </tr> <tr> <td colspan="3" bgcolor="#CECFCE" class="menu-bor"><br />' . include ("rss.php") . '<br /></td> </tr> </table>'; } ?>
  7. This means there is either something wrong with your query, or there are no results. Try this: <?php foreach($array as $item){ $result = mysql_query("SELECT * FROM names WHERE id = '$id'") or die(mysql_error()); $num = mysql_num_rows($result); if($num > 0){ while($row = mysql_fetch_array($result)){ $row['Firstname']." - ". $row['Surname'] ." ".$row['Sex']; } } } ?>
  8. No, type casting doesn't have the effect of rounding a decimal, it actually has the effect of rounding down.
  9. Im surprised it's working at all, mysql_query() returns a result resource - not the actual result of the query. Try: <?php $sql = mysql_query("SELECT COUNT(NID) FROM news"); $numrows = mysql_result($sql,0); $rowsPerPage = 20; $maxPage = ceil($numrows/$rowsPerPage); ?> And yes, you do need to be rounding up the number.
  10. Corr, i'd love to know what i was thinking when i posted that code. It needs to be a while loop: <?php //get stuff from db // Make the connection $db = mysql_connect($myHost, $myUser, $myPass); // Select the database mysql_select_db($myDB,$db); $sql = "SELECT * from $myTable ORDER BY RAND() LIMIT 8"; // Get the query object @$result=mysql_query($sql,$db); // How many rows? $numRows = mysql_num_rows($result); // Initialise output $output = ''; while($row = mysql_fetch_assoc($result)){ $output .= '<TD>user=' . $row['user'] . 'victim=' . $row['victim'] . '</TD>'; etc } // Close the database connection mysql_close($db); In my defence, i do have a cold
  11. You don't use single quotes for starters. You use single quotes to enclose strings within you query. The character i used was the backtick (`) - which you can use to surround table names, field names etc. You don't have to do this, but i think it looks cleaner and easier to read. Anyway, Try: <?php $sql2 = "SELECT COUNT(*) AS `num`,`victim` FROM `victims` GROUP BY(`victim`) ORDER BY `num` DESC LIMIT 1"; @$result2=mysql_query($sql2,$db); if($result2){ $row = mysql_fetch_assoc($result2); echo 'The most popular victim is: '.$row['victim'].' who has been the victim on '.$row['num'].' occassions'; } ?> Not quite sure why being the victim makes you popular, but yeah!
  12. As you would any other fuction? Or have i misunderstood: <?php function writeShoppingCart() { } $action = $_GET['action']; switch ($action) { case 'add': writeShoppingCart(); break; } function displayShoppingCartItems() { } ?>
  13. You can do it all with the mysql query, and use a foreach loop: <?php //get stuff from db // Make the connection $db = mysql_connect($myHost, $myUser, $myPass); // Select the database mysql_select_db($myDB,$db); $sql = "SELECT * from $myTable ORDER BY RAND() LIMIT 8"; // Get the query object @$result=mysql_query($sql,$db); // How many rows? $numRows = mysql_num_rows($result); // Initialise output $output = ''; foreach($row as mysql_fetch_assoc($result)){ $output .= '<TD>user=' . $row['user'] . 'victim=' . $row['victim'] . '</TD>'; etc } // Close the database connection mysql_close($db);
  14. You need to specify an enctype in your form: <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="formnewuser" id="formnewuser"> Without that, the server isn't expecting file as well as the other form data.
  15. Do you think you could explain again? Maybe it's just me, but i've no idea what you're actually trying to achieve.
  16. What does the mysql table look like? Im a little confused as to how you arrive with this information. Do you have an ID for each connection and a record for each stage perhaps? Maybe if you post the array you have and the array you would like it would help.
  17. I disagree. Often regex is the most secure way of validation. Making sure data matches an expected pattern is often more secure than more general constraints on type and length. Of course, in this example, it acheives the same thing; though the regex approach is marginally slower.
  18. How about: SELECT COUNT(*) AS `num`,`name` FROM `yourtable` GROUP BY(`name`) ORDER BY `num` DESC If you do just want the most popular, rather than an ordered listing of popularity, stick a LIMIT clause on the end: SELECT COUNT(*) AS `num`,`name` FROM `yourtable` GROUP BY(`name`) ORDER BY `num` DESC LIMIT 1
  19. Yeah, of course - we are talking about the very tiny overhead of using regular expressions. Either i'm a perfectionist or it's just the fact that i hate working with regex... To be honest, it's probably the latter
  20. Very strange. Out of interest, what version of PHP are you running? I assume the issue lies somewhere with 'today'. It works fine for me locally under 5.1.6 and fine on a host which is running 5.2.4.
  21. Personally i'd use the ctype_digit() and strlen() functions rather then using the preg_replace function, since regular expressions are slow.
  22. The code i posted works fine for me. Are you sure you copied it exactly? You didn't change a minus to a plus by accident?
  23. strtotime() is your friend: <?php for($i = 0;$i<6;$i++){ $time = strtotime("today - $i months"); echo date("m M",$time).'<br />'; } ?>
  24. Well, are you deleting the data from your cbox_msgs table? If not, you could just count the number of posts by each user - no need for an extra field. Otherwise, yes, you will need a new field. Presumably you have a table with the user data. Simply add a new column into this table, perhaps called cbox_posts. Then, just after inserting the message into your cbox_msgs table, increase the number in this field by 1: <?php //the rest of your code if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_query("UPDATE `yourusertable` SET `cbox_posts`=`cbox_posts`+1 WHERE `username`= '$session->username'") or die(mysql_error()); echo "Your message has been posted. <a href='cbox.php'>[back]</a>"; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.