Jump to content

worldcom

Members
  • Posts

    15
  • Joined

  • Last visited

Everything posted by worldcom

  1. Sorry wasn't talking about your code. It works great. It was this quote I was referring too:
  2. Also, what if I deleted a banner or 2 and there was NO id for that random selection. Thanks for the mySql solution Psycho. All the help has been great.
  3. OK my new and improved code. <?php require('members/connect.php'); // Get a count of the banners available $query = "SELECT COUNT(*) AS RowCount FROM banners WHERE banner_size=7"; $result = mysqli_query($dbc, $query); $banner = mysqli_fetch_array($result); $num_rows = $banner['RowCount']; mysqli_free_result($result); // Pick a random number and subtract 1 (we want the OFFSET) $randomOffset = rand(1, $num_rows) - 1; // Select the banner $query = "SELECT http_url, onMouseDown_site, title, banner_url FROM banners WHERE banner_size = 7 LIMIT $randomOffset, 1"; $result = mysqli_query($dbc, $query); $banner = mysqli_fetch_array($result); mysqli_free_result($result); ?> <a href="http://<?php echo $banner[0]; ?>">. . . My banner stuff here . . .</a> Works great. Thanks for your help.
  4. Thanks DavidAM, I got it working but I'm gonna use your code. I'll just post how I got my code working. <?php require('members/connect.php'); $query = "SELECT * FROM banners WHERE banner_size=7"; $result = mysqli_query($dbc, $query); $random_banner = rand(1, mysqli_num_rows($result)); $i = 0; while( $banner = mysqli_fetch_array($result) ){ $i++; if( $i == $random_banner ){ ?> <a href="http://<?php echo $banner[2]; ?>" all my banner stuff here </a> <?php } } ?> This works, but I am taking your advice. My new code here is very clunky.
  5. I do have a column id. But I can't let it select a random number because the auto_increment numbers may not be in order. eg 3 certain size banners can be id's 2,10, 15 What I need is, the random number to select the id 2 or 10 or 15 but the random number is between 1 and 3. Hope I'm explaining it right.
  6. Hey all, I'm making this little script to rotate banners. I'm having a brainurisim right now trying to think how to grab one random row from the database. Here's what I have: <?php require('members/connect.php'); $query = "SELECT * FROM banners WHERE banner_size=7"; $result = mysqli_query($dbc, $query); $banner = mysqli_fetch_array($result); $num_rows = mysqli_num_rows($result); echo "$num_rows - ". rand(1, $num_rows) ."<br>"; // This is just to check the numbers ?> So for example, if the random number is 2, how can I select the 2nd row from the query database. I have various sizes of banners in the database, so I'm only selecting one particular size ( banner_size= 7 ). I know if I just use the $banner[array], it will just return the first one found. I have a feeling this is going to be too simple and I will have a red face
  7. I'll have a good look. Just an FYI, I just was pointing out to the OP that you should be checking any input. Also, I'm not sure if we should't be relying on $_SERVER['REQUEST_METHOD'], you should know the method of what you expect either $_GET or $_POST.
  8. @PaulRyan you are correct. Me bad. Been a while but I usually put in a hidden post value that I check instead of just the button. eg. <input type"hidden" value="TRUE" name="form_submitted"> I should look at some of my older scripts
  9. This is my preference for forms. I don't check the method. I want to check that the login form has been submitted. Also, be sure to escape your data from bad people if( isset($_POST['your_form_submit_button_value']) ){ $password = mysql_real_escape_string($_POST['password']); $username = mysql_real_escape_string($_POST['username']); .... // the rest of your code
  10. I should have read that, but you may want to change your code anyway: <?php session_start(); if (isset($_SESSION['username'])) { echo "Welcome, ".$_SESSION['username']."!<BR> echo "<a href=\"logout.php\">LOGOUT</a>"; } else { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href=\"index.php\">GO BACK</a>and try again"; } ?> It just makes a bit more sense
  11. You must start the session first: <?php session_start(); if (isset($_SESSION['username'])) { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href=\"index.php\">GO BACK</a>and try again"; } else { if ($_SESSION['username']) { echo "Welcome, ".$_SESSION['username']."!<BR> echo "<a href=\"logout.php\">LOGOUT</a>"; } ?>
  12. My simple answer for the 'collision' possibility. When I am storing a password for a user, for example, it is stored with an incremented value as an ID in the database. Should an MD5 hash of a password match another one, it will NEVER match the combination of the ID value (incremented value) + the hash value.
  13. In your <FORM> tag, you are not calling the javascript. Use onsubmit="yourjavascriptfunction()" and you really do need php vailidated regardless of what your processor says
  14. $catid = $_GET['catid']; if(isset($_GET['subid'])){ $subid = $_GET['subid']; }else $subid = '%'; ?> I know you have it solved but you could try putting a wildcard in for $subid ( % ) and it should return all subid results with only 1 query.
  15. <?php $id = (int)$_GET['id']; $months = array( 1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); if( !empty($_GET['month_name']) ){ $month_name = $_GET['month_name']; } else { $month_name = date("F"); } $this_year = date("Y"); $today = date("d"); $month = date("m"); $event_day = date("j"); $this_month = $month_name .' '. $today .' '. $this_year; $month_num = date("n", strtotime("$this_month")); $first_day = date("w", strtotime("1 $month_name $this_year")); $num_days = date("t", strtotime("1 $month_name $this_year")); $prev_month = date("F", strtotime("$this_month -1 month")); $next_month = date("F", strtotime("$this_month +1 month")); ?> <?php $query = "SELECT id, EXTRACT(DAY FROM date) FROM calendar WHERE (location={$_SESSION['location']} OR location=3) AND EXTRACT(MONTH FROM date)=$month AND EXTRACT(YEAR FROM date)=$this_year"; $result = mysql_query($query); $num = mysql_num_rows($result); if( $num > 0 ){ while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $month_info[$row[1]] = $row[0]; } } if( $month_info[$event_day] > 0 ){ echo "<DIV STYLE='position: absolute; top: 1px; left: -45px;'><A HREF='event_page.php?id=$month_info[$event_day]'><IMG SRC='images/today.gif' WIDTH='95' HEIGHT='57' BORDER='0'></A></DIV>"; } ?> <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#000000"><TR><TD> <TABLE WIDTH="100%" BORDER="0" CELLSPACING="1" CELLPADDING="2" BGCOLOR="#000000"> <TR ALIGN="center" BGCOLOR="#C1C1FF"><TD COLSPAN="7"><FONT SIZE="1" COLOR="#000000" FACE="Verdana"><?php echo "$month_name $this_year"; ?></TD></TD></TR> <TR ALIGN="center" BGCOLOR="#FFFFD5"><TD WIDTH="10"><FONT SIZE="1" COLOR="#000000" FACE="Verdana">S</TD> <TD WIDTH="10"><FONT SIZE="1" COLOR="#000000" FACE="Verdana">M</TD> <TD WIDTH="10"><FONT SIZE="1" COLOR="#000000" FACE="Verdana">T</TD> <TD WIDTH="10"><FONT SIZE="1" COLOR="#000000" FACE="Verdana">W</TD> <TD WIDTH="10"><FONT SIZE="1" COLOR="#000000" FACE="Verdana">T</TD> <TD WIDTH="10"><FONT SIZE="1" COLOR="#000000" FACE="Verdana">F</TD> <TD WIDTH="10"><FONT SIZE="1" COLOR="#000000" FACE="Verdana">S</TD></TR><TR ALIGN='center' BGCOLOR='#FFFFFF'> <?php for( $i=0; $i<=41; $i++ ) { echo "<TD HEIGHT='10'"; if( $month_info[($i-$first_day+1)] > 0 ){ if( ($i-$first_day+1) >= $event_day ){ if( $location_info[($i-$first_day+1)] == 1 ){ echo " BGCOLOR='#008000'"; } else { echo " BGCOLOR='#0000FF'"; } } else { echo " BGCOLOR='#FF8484'"; } } elseif( $today == ($i-$first_day+1) ){ echo " BGCOLOR='#BBFFFF'"; } echo "><FONT SIZE='1' COLOR='#000000' FACE='Arial'>"; if( $i < $first_day || $i >= ($first_day + $num_days) ){ echo " "; } else { if( $month_info[($i-$first_day+1)] > 0 ){ echo "<A HREF='event_page.php?id=". $month_info[($i-$first_day+1)]; if( ($i-$first_day+1) >= $event_day ){ echo "' STYLE='color: #FFFFB7;"; } else { echo "' STYLE='color: #000000;"; } echo " text-decoration: none;'>". ($i-$first_day+1) ."</A>"; } else { echo ($i-$first_day+1); } } echo "</FONT></TD>"; if( $i == 6 || $i ==13 || $i ==20 || $i ==27 || $i ==34 ){ echo "</TR><TR ALIGN='center' BGCOLOR='#FFFFFF'>"; } } echo "</TR></TABLE></TD></TR></TABLE></BODY></HTML>"; ?> You can try this one. I use it as an include file and it will hi-light event days that you can link to another page to display the event details. Your sql database uses columns: id (auto_increment) || date || event_description || anything else you want The id is the value extracted and passed on to the event page. Tweat it out as you need
×
×
  • 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.