Jump to content

defroster

Members
  • Posts

    89
  • Joined

  • Last visited

Everything posted by defroster

  1. If anyone knows if there is a difference in using 1 or -1 would be very much appreciated thanks
  2. Thanks. You mention earlier you would use negative one (-1) for a vote up and 0 for a vote down. Is there any advantage using a negative one (-1) as opposed in using a positive one (1)? Thanks /df
  3. Ok, so my understanding is that I am doing the correct thing then? Please confirm. The code I am using however generates nothing, as the <option value=''> just is blank.. Must be doing something wrong Thanks so much for help!
  4. When I am trying to set up the 'vote' table in phpmyadmin. I select BOOL, but then when after it is created it says TINYINT(1) ?? Is this normal, or am I doing something wrong? Thanks
  5. Hello, 1. I have a page called video.php, where people can view a video of a specific id. (video.php?id=1) 2. Within this page if 'logged in administrator' should be possible to edit title and category 3. Now I need to do a loop to receive all the categories from my table called category so I have the possibility to change category. Table: categories Table: videos ------------------ ------------------- id (int) id (int) cat_id (int) cat_id(int) cat (varchar) title (varchar) I was trying to do something like below but I am not doing it right. How do I do this query? I have been trying like the code below using to queries ($sql and $sql2). I am suspecting I need to use JOIN query or similar instead of having two queries? Help is very <?php $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); $sql = "Select videos.*, categories.cat FROM videos, categories WHERE videos.id =" . $_GET['id']; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo "<h2><a href='video.php?id=" . $row['id'] . "'>" .$row['title'] . "</a></h2>"; //Admin stuff Users.Setting=1 if($_SESSION['setting'] == 1) { echo "<form name='update' method='post' action='update.php'><input type='hidden' name='id' value='". $row['id']. "'>"; echo "<input type='text' name='title' value='". $row['title'] . "' size='100'><br>"; $sql2 = "Select * FROM categories"; $result2 = mysql_query($sql2) or die(mysql_error()); $row2 = mysql_fetch_assoc($result2); echo "<SELECT NAME='categories'>"; while($row2 = mysql_fetch_array($result2)); { echo "<OPTION VALUE='". $row2['id'] ."'>". $row2['cat']; } echo "</SELECT>"; echo "<input type='submit' name='update' value='update'><br>"; } ?> -- VIDEO IS DISPLAYED HERE ---- <?php echo "<br><i>In <a href='cat.php?id=" . $row['cat_id'] ."'>" .$row['cat']. "</a>"; echo "<hr>"; ?> Help is very much appreciated. THanks /df
  6. Thanks a million. That is what I'll try doing then. /df
  7. Thanks for reply, yes they should only be allowed to vote once per video.
  8. I found the problem. Thanks all anyway. I hade several forms on the same page and the form below were sending the parameters. Problem solved. Good night
  9. Hello, I have sat for hours now with this code. It runs without errors but will not update the changes in the database. What am I doing wrong? I am a beginner at this. Thanks a million /df <?php session_start(); require ("incl/config.php"); require ("incl/functions.php"); //Admin stuff Users.Setting=1 if($_SESSION['setting'] == 1) { $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); $id=$_POST['id']; $title=$_POST['title']; $titletext=$_POST['titletext']; $url=$_POST['url']; $dateposted=$_POST['dateposted']; // To protect MySQL injection $title = stripslashes($title); $titletext = stripslashes($titletext); $url = stripslashes($url); $dateposted = stripslashes($dateposted); $title = mysql_real_escape_string($title); $titletext = mysql_real_escape_string($titletext); $url = mysql_real_escape_string($url); $dateposted = mysql_real_escape_string($dateposted); mysql_query("UPDATE Videos SET title='$title', titletext='$titletext', url='$url', dateposted='$dateposted' WHERE id='$id'"); echo mysql_error(); } ?>
  10. Hello, I am planning on adding a voting system for videos on my website. Setting up the database. Which is better? 1. To have the votes included in the same table as the video information Table videos ------------------------- id (int) name (varchar) upvotes (int) downvotes(int) 2. Have a separate table called 'votes' in connection with the videos table that have the following colums, that looks like this. Table votes --------------- id (int) video_id (int) upvote (int) downvote(int) - If #2 is the best solution, would you use each vote to be one row in the database, or just to update the 'total vote count' for each corresponding video? i.e. id/video_id/upvote/downvote --------------------------------------- 01/055/1333/100 (Example: 1333 votes up and 100 votes down) Thanks so much for help /df
  11. Ahh thanks. I thought I had to get the function with code telling to get in some way. But now I changed it to: $pasttime=TimeAgo($row['dateposted'],$dateto=-1); Thanks for help! problem solved
  12. Ok, thanks a lot for your help. Really appreciate it. I did not know that '@' meant those things. Beginner at this. Now I get error: Fatal error: Call to undefined function get_TimeAgo() in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 157 and line 157 is: $pasttime=get_TimeAgo($row['dateposted'],$dateto=-1); How do I call for the function then?
  13. I am having huge problems with this, I don't get any error message and the html output just freezes. Any idea what can be wrong? $pasttime=@get_TimeAgo($row['dateposted'],$dateto=-1); echo "time:" . $pasttime. "since post"; Function: function TimeAgo($datefrom,$dateto=-1) { $datefrom = strtotime($datefrom); // Defaults and assume if 0 is passed in that // its an error rather than the epoch if($datefrom<=0) { return "A long time ago"; } if($dateto==-1) { $dateto = time(); } // Calculate the difference in seconds betweeen // the two timestamps $difference = $dateto - $datefrom; // If difference is less than 60 seconds, // seconds is a good interval of choice if($difference < 60) { $interval = "s"; } // If difference is between 60 seconds and // 60 minutes, minutes is a good interval elseif($difference >= 60 && $difference<60*60) { $interval = "n"; } // If difference is between 1 hour and 24 hours // hours is a good interval elseif($difference >= 60*60 && $difference<60*60*24) { $interval = "h"; } // If difference is between 1 day and 7 days // days is a good interval elseif($difference >= 60*60*24 && $difference<60*60*24*7) { $interval = "d"; } // If difference is between 1 week and 30 days // weeks is a good interval elseif($difference >= 60*60*24*7 && $difference < 60*60*24*30) { $interval = "ww"; } // If difference is between 30 days and 365 days // months is a good interval, again, the same thing // applies, if the 29th February happens to exist // between your 2 dates, the function will return // the 'incorrect' value for a day elseif($difference >= 60*60*24*30 && $difference < 60*60*24*365) { $interval = "m"; } // If difference is greater than or equal to 365 // days, return year. This will be incorrect if // for example, you call the function on the 28th April // 2008 passing in 29th April 2007. It will return // 1 year ago when in actual fact (yawn!) not quite // a year has gone by elseif($difference >= 60*60*24*365) { $interval = "y"; } // Based on the interval, determine the // number of units between the two dates // From this point on, you would be hard // pushed telling the difference between // this function and DateDiff. If the $datediff // returned is 1, be sure to return the singular // of the unit, e.g. 'day' rather 'days' switch($interval) { case "m": $months_difference = floor($difference / 60 / 60 / 24 / 29); while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) { $months_difference++; } $datediff = $months_difference; // We need this in here because it is possible // to have an 'm' interval and a months // difference of 12 because we are using 29 days // in a month if($datediff==12) { $datediff--; } $res = ($datediff==1) ? "$datediff month ago" : "$datediff months ago"; break; case "y": $datediff = floor($difference / 60 / 60 / 24 / 365); $res = ($datediff==1) ? "$datediff year ago" : "$datediff years ago"; break; case "d": $datediff = floor($difference / 60 / 60 / 24); $res = ($datediff==1) ? "$datediff day ago" : "$datediff days ago"; break; case "ww": $datediff = floor($difference / 60 / 60 / 24 / 7); $res = ($datediff==1) ? "$datediff week ago" : "$datediff weeks ago"; break; case "h": $datediff = floor($difference / 60 / 60); $res = ($datediff==1) ? "$datediff hour ago" : "$datediff hours ago"; break; case "n": $datediff = floor($difference / 60); $res = ($datediff==1) ? "$datediff minute ago" : "$datediff minutes ago"; break; case "s": $datediff = $difference; $res = ($datediff==1) ? "$datediff second ago" : "$datediff seconds ago"; break; } return $res; } Thanks for help!!
  14. Hello, I am not a programmer but I just got this from godaddy. How can I change this problematic script? Thanks /D. Froster It has come to our attention that your hosting account, specifically the database is causing the shared resources to be over-utilized. This, in turn, affects the usage by other customers. We have disabled your database to return the server to normal usage. To re-enable your database, you will need to correct the following query: -Problematic query: SELECT * , count(*) as count FROM pligg_links , pligg_categories WHERE category_lang='en' AND category_id=link_category GROUP BY link_category ORDER BY category_name ASC EXPLAIN: id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY pligg_categories ALL 31 Using where; Using temporary; Using filesort 2 DEPENDENT SUBQUERY pligg_links ALL 4619 Using where This query examines 143189 rows Problematic query: SELECT link_id FROM pligg_links WHERE link_status='published' ORDER BY (SELECT SUM(vote_value) FROM pligg_votes WHERE vote_link_id=link_id) DESC LIMIT 15,5 EXPLAIN: id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY pligg_links ALL 4619 Using where; Using filesort 2 DEPENDENT SUBQUERY pligg_votes ref link_id link_id 4 pnktn.pligg_links.link_id 37 This query examines 170903 rows, which is unacceptable in shared hosting.
×
×
  • 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.