m11oct
-
Posts
7 -
Joined
-
Last visited
Never
Posts posted by m11oct
-
-
Can you tell me what the query I would need would look like?
Thanks -
I have TABLE1 with column A where A is a unique index. (Say topics on a forum, for example.)
I have TABLE2 with columns B, C and D where B is the unique index and C will refer to one of the rows in TABLE1. (Say posts on a forum, where C identifies to which topic the post belongs and D is the time of the post.)
I would like be able to...
For each row (value of A) in TABLE1, identify the row (value of B) in TABLE2 where C=A and D is greatest (i.e. greater than any other value of D where C=A).
I am currently using the following code but it is very slow:
$res=query("SELECT a FROM table1");
while ($row=mysql_fetch_row($res)) {
$res2=query("SELECT b,c,d FROM table2 WHERE c=".$row[0]." ORDER BY d DESC");
//the above will return one result which will be $result
echo $row[0] . ';' . $result;
}
I would like to be able to just have one query and run through the loop without having to do another query in the loop.
Thank you -
That works well, thank you very much.
-
If you don't know about MySQL syntax then please just ignore this post...
I'm having a MySQL Query problem as I don't know how to write it...
I want to select columns B and C from TABLE2 if the value from C in TABLE1 doesn't exist as a column A in TABLE1 at all.
Column A is the index for TABLE1 and column B is the index for TABLE2 while column C in TABLE2 refers to a row from TABLE1.
However, it appears there are quite a lot of cases in TABLE2 where the row column C referes to in TABLE1 no longer exists and I'd like to be able to select all of these.
Any ideas? -
I already tried that. It didn't work. I got the same error.
-
Hello,
I've experienced a problem trying to access URLs which have a hyphen in certain areas of the URL. The URL is constructed like this: "something-.example.com" where the hyphen is immediately before the .example.com bit.
The error received is:
Warning: fopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in ---.php on line 105
Warning: fopen(--): failed to open stream: Permission denied in ---.php on line 105
Is there a workaround for this?
Thanks
query problem (relating to wiki)
in MySQL Help
Posted
There is a script in the software which automatically selects a random page for the user to view.
The code (contained in the file "SpecialRandompage.php") is:
[code] $randstr = wfRandom();
$db =& wfGetDB( DB_SLAVE );
$use_index = $db->useIndexClause( 'page_random' );
$page = $db->tableName( 'page' );
$extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : '';
$sql = "SELECT page_id,page_title
FROM $page $use_index
WHERE page_namespace=$namespace AND page_is_redirect=0 $extra
AND page_random>$randstr
ORDER BY page_random";
$sql = $db->limitResult($sql, 1, 0);
$res = $db->query( $sql, $fname );[/code]
My problem is that there are certain pages which I would like to exclude from being selected when a user wants to view a random page. The pages which I don't want to be selected randomly are "disambiguation" pages. The problem is that unlike "page_is_redirect", there is no "page_is_disambiguation" field in the database.
In the wiki, all disambiguation pages are also categorised into a category called "Disambiguation". This results in them being listed in a different table of the database (tablename: categorylinks). In this table, "page_id" in the first table would match the value of "cl_from" in the categorylinks table. There may be more than one row with a matching "cl_from" value. If the page is a disambiguation, there would be a row where "cl_from" matched "page_id" and "cl_to" was equal to text string "Disambiguation".
Any ideas how I would change the SQL query in the code? I am quite experienced with PHP but just need a little guidance on the SQL code.
Thanks in advance,
Michael