vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Stuck.... (https://vborg.vbsupport.ru/showthread.php?t=39163)

Matt 05-28-2002 08:23 PM

Stuck....
 
:paranoid: Me thick....

:o Me need help........

:rolleyes:

Whats wrong with this please? I am so confused with what this even does lol so if someone could exlplain that would be great :D

Code:

$query = "SELECT fanfic_authors.name, fanfic_authors.email, fanfic_contents.author, fanfic_contents.title, fanfic_contents.rating FROM fanfic_authors, fanfic_contents WHERE fanfic_authors.id = fanfic_contents.author GROUP BY fanfic_contents.author, fanfic_contents.title ORDER BY " . $sort . ",title LIMIT " . $start . ", 50";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){
print($row[title] . "<br>");
}


Dark_Wizard 05-28-2002 09:51 PM

Whoa! Can you post the db schema? Both tables that is...then we can go from there...

Matt 05-29-2002 12:02 AM

Thanks!

fanfic_authors
id int(11) NOT NULL auto_increment,
name varchar(100) NOT NULL default '',
email varchar(100) NOT NULL default '',
PRIMARY KEY (id)
TYPE=MyISAM;

fanfic_contents
id int(11) NOT NULL auto_increment,
title varchar(255) NOT NULL default '',
disclaimer text NOT NULL,
summary text NOT NULL,
spoilers text NOT NULL,
season int(11) NOT NULL default '0',
author int(11) NOT NULL default '0',
rating int(11) NOT NULL default '0',
content text NOT NULL,
notes text NOT NULL,
PRIMARY KEY (id)
TYPE=MyISAM;

Matt 05-29-2002 12:08 AM

Just so you know what its for I am trying to do a fan fiction archive for my site and looked at someone elses code which was set out similar to this. Before that I had :

SELECT * FROM fanfic_contents ORDER BY..........

I just wanted somehow to make it a bit easier and to involve less queries. The problem being that the author info and the actual fan fiction are stored in different tables.

So I basically have this code and have a vague idea of what its doing but no real understanding of it :S

Logician 05-29-2002 08:56 AM

You didnt write what kind of result you want your query to return but at the first glance it seems that GROUP BY is redundant in this query..

If what you want to return is ALL results in fanfic_authors table (combined with relevant results from the contents table), this should work fine:

$query = "SELECT * FROM fanfic_authors a, fanfic_contents c WHERE a.id = c.author";

Matt 05-29-2002 11:26 AM

Basically I am trying to code the page where it lists the authors/titles/ratings etc 50 to a page. With a next link at the bottom if there are more than 50 results stored in that category.

I just thought that there would be an easier way to me doing like 10 queries. One to get the authors name and email, one to get the rating, one to get the title etc....

So I really want :

AUTHOR TITLE RATING CHAPTERS
Matt Title Here G [1] [2]

Something like that basically. Then when you click on the header of each column it will sort the results by that.

Logician 05-29-2002 12:05 PM

Ok, modifying my code with LIMIT and SORT should do the trick, like:

$query = "SELECT * FROM fanfic_authors a, fanfic_contents c WHERE a.id = c.author AND a.id>$var ORDER BY ".$sort." LIMIT 50 ";

Now you have to pass your script the last pulled author id as $var, like:

while($row = mysql_fetch_array($result))
{
print($row[title] . "<br>");
$var=(int)$row[author];
}

If there are more than 50 records call your script like:
'<a href="yourscript.php?var='.$var.'>click here to get more</a>'

Needless to say in the first run, $var=0

Matt 05-29-2002 09:11 PM

Anywhere you would suggest that I would find a good tutorial for all this as I still don't totally get it and I will need to adapt it to other areas as well.

Thanks for your help so far :)

Logician 05-30-2002 05:47 AM

sorry I dont know a basic tutorial for this feature on the net, but if you can find it somewhere and study it for a while then you can check "forumdisplay.php" and "showthread.php" of vb to get an advanced lesson. They use the same method. But their structure is way to complex for a newbie


All times are GMT. The time now is 07:15 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01019 seconds
  • Memory Usage 1,728KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete