Jump to content

defonic

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Everything posted by defonic

  1. Thanks, I searched the site but time was not on my side! I figured it out and might as well post the solution for future members. SELECT * FROM table WHERE id BETWEEN ( SELECT (MAX(id)-50) FROM table) AND ( SELECT (MAX(id)) FROM table) ORDER BY RAND() LIMIT 3 This will get the last 50 records (assuming there is auto increment on id) then randomly choose 3
  2. Hello All, Having issues with a shared hosting account using to much RAM/CPU on my site Currently using: SELECT * FROM table ORDER by RAND() LIMIT 3 Problem is I have over 200,000 rows. Is there a way to... (pseudo) select * from table where id between max(id) and max(id) -50 ? so it only returns the last 50 rows then do a order by rand() limit 3? Does this type of query exsist? and if so will it speed up the query by only selecting rand from last 50 rows? any help appreciated!
  3. With your help I solved it, Thank you! $alines=file('data.txt'); $dlines=array_slice($alines,0, -5); $fileContents=implode($dlines); $fp=fopen('data.txt','w+'); fwrite($fp,$fileContents); fclose($fp);
  4. Every time I try I end up removing everything except the last 5 lines.
  5. Extremely new here and to PHP and I have exhausted my newbie resources and my brain on this one. :'( Concept: Cron Job to INSERT 5 lines per hour (Not the whole list at once) [*]Script to read a pipe delimited text file (about 5k Lines) [*]Open File Get last (bottom) 5 lines of file, ignore the rest [*]Insert those 5 lines into my database [*]Open File, Remove last (bottom) 5 lines I am able to do parts 1-3 but not part 4 (removing last 5 lines) Please help me! $data = array_slice(file('data.txt'), -5); foreach($data as $value) { $fields=explode("|",$value); $num=count($fields); for ($n=0;$n<$num;$n++) { $null=""; print ($n==0) ? "Importing Video...<BR>" : $null; } // Insert into tmpvideos table here include("includes/config.php"); $last_id_result = @mysql_query( @"SELECT ext_id FROM tmpvideos ORDER BY ext_id+0 DESC, id DESC" ); if ( 0 < @mysql_num_rows( $last_id_result ) ) { $last_id = @mysql_result( $last_id_result, 0, "ext_id" ) + 1; } else { $last_id = "1"; } copy($fields[3], "thumbs/ex_".$last_id.".jpg" ); $fields[3] = "thumbs/ex_".$last_id.".jpg"; set_time_limit(0); mysql_query("INSERT into tmpvideos (id, ext_id, title, description, duration, category, date_added, thumb, video, views, rating, votes, status) VALUES ('','".$last_id."','$fields[0]','$fields[1]','$fields[5]','$fields[6]',NOW(),'$fields[3]','$fields[2]','','','','1')"); } I understand the 'concept' but am unable to grasp the code! I have tried many snippets and really need help.
  6. Yes this gives me an output off the count in each category, this is what I have. <?php include("includes/config.php"); $result=mysql_query("SELECT COUNT(*) cnt FROM videos GROUP by category;"); while($row=mysql_fetch_assoc($result)){ ?> <?=$row['cnt']; ?> videos in category <?=$row['category']; ?> <? } ?> <?=$row['category']; ?> above doesn't show up. How would I do 2 select statements to be able to capture 'category' I want it to display like "112 videos in category 72"
  7. Ok thanks for everyone's help, again I am new at this and need to figure this out on my own since my programmer went MIA. After better research this is what I have. Table videos under the videos table I have id, title, date_added, category So the category is a number, so I may have "comic book #4, 76" 76 being a category. So i need to count how many 76 there are and so on. This is I need to output this in a simple fashion.
  8. the template is using smarty here is the line I have to reference: {foreach from=$array_categories item=category name=categ} <a href="./categ/{$category.id}/{$category.title}/" class="link"><b>{$category.title} I am assuming it is category
  9. Thanks for everyones help, I am new to SQL so heres what I have, I am trying to output it now like so: <?php include("includes/config.php"); $result=mysql_query("SELECT COUNT(*) AS cnt FROM category GROUP BY title;"); while($row=mysql_fetch_assoc($result)){ ?> <title><?=$row['title']; ?></title> <id><?=$row['id']; ?></id> <? } ?> Does not seem to work, am i doing something wrong here?
  10. Hello, first off I would like to say hello! I have a mySQL question regarding counting and getting a sum. I run a streaming cartoon video site, I paid a freelancer to make the script now he is MIA. I have a database table named 'categories' inside 'categories' is: id, title eg; (id)0001 (title)Comics, (id)0002 (title)Funnies Is there a way to count how many "id's" there under a specific title? I want to be able to display how many videos are in each category. Can someone help me with accomplishing this, or maybe tell me where to look? I am not looking for a free handout I am just trying to figure out where to begin. Thanks!
×
×
  • 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.