|
I am trying to order them by primkey.
Each new score has a higher primkey, so the latest will be with the highest number and thats why i was trying to order them by primkey
Hope this helps
|
|
|
|
|
Read the documentation[^]
ORDER BY `primkey` DESC
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Thanks, i fixed it and its compiling now but i cant get the scores out
Here is the function:
function am_getlatestscores($db, $cat) {
global $db;
$sql = "SELECT * FROM `AMCMS_highscores` JOIN `AMCMS_users` WHERE `primkey`=`username` ORDER BY `primkey` DESC LIMIT 10;";
$res = am_queries($db, $sql);
return $res;
}
Here is how i output them in another file:
$higharray = am_getlatestscores($db, 'none', 'list');
foreach ($higharray as $hhscore) {
echo '<font><a href="./index.php?cat='.hhscore.'">$hhscore</a></font>
But it wont output anything I am sorry if its very simple but i am learning
|
|
|
|
|
djkee wrote:
echo '<a href="./index.php?cat='.hhscore.'">$hhscore</a>';
You're missing the $ in front of hhscore. That and hhscore is an array. The array can be accessed by either numerical or string keys.
You can use $hhscore[ 'column1' ] or $hhscore[ 0 ] depending on your preference is.
I'm not saying that they will both work as I don't know whether $hhscore is associative or not (or both).
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
I tried using $hhscore[ 0 ] but the script just crashes
What do you mean by if $hhscore is associative or not (or both) ??
With that mysql query and the echo should i be able to get the records from the database ?
This is error i get:
Warning: Invalid argument supplied for foreach() in /home/myusername/public_html/cache/%%45^45E^45E480CD%%index.tpl.php on line 37
Thank you for all the help
modified on Wednesday, November 25, 2009 6:24 AM
|
|
|
|
|
After saying what I said before, it may not even be an array, what exactly do you have in am_queries() ?
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Here is the function am_queries
function am_queries($db, $sql, $verboseErr=3, $cacheCmd=1, $cache_dir = './cache/') {
global $cache_config;
global $cache_page_time;
global $numberOfQueries;
$exempt = false;
$checkOne = explode(' ', $sql, 2);
if (strtoupper($checkOne[0])=='INSERT' || strtoupper($checkOne[0])=='UPDATE' || strtoupper($checkOne[0])=='CREATE' || strtoupper($checkOne[0])=='DROP' || strtoupper($checkOne[0])=='DELETE') {
$exempt = true;
}
These are the errors i get when trying to output the query.
Warning: Missing argument 2 for am_getlatestscores(), called in /home/myusername/public_html/cache/%%45^45E^45E480CD%%index.tpl.php on line 36 and defined in /home/myusername/public_html/includes/gamefunctions.php on line 491
Warning: Invalid argument supplied for foreach() in /home/myusername/public_html/cache/%%45^45E^45E480CD%%index.tpl.php on line 37
Thanks for helping me fly904
modified on Wednesday, November 25, 2009 2:39 PM
|
|
|
|
|
if I may...
your first warning is that your are missing the 2nd argument in your function am_getlatestscores, which is $sql. This warning is being called from called in /home/myusername/public_html/cache/%%45^45E^45E480CD%%index.tpl.php on line 36. Open this php script and go to line 36 and look at how the $sql argument is built and passed. Also count your arguments you have 5 listed, but only the last 3 have default values. So you MUST have at least 2 arguments in the function call.
The foreach is expecting an array to be passed, and it is not present.
the 2 common usages of foreach is:
foreach($myArray as $value)
{
echo "Val: ".$value." ";
}
...or...
foreach($myArray as $key=>$value)
{
echo "Key:".$key." Val: ".$value." ";
}
given an array of...
$myArray = array(a,b,c);
The first foreach will produce...
Val: a
Val: b
Val: c
The second foreach....
Key: 0 Val: a
Key: 1 Val: b
Key: 2 Val: c
So long story short, the value you have passed to your foreach is not an array.
looking back at your code...
$higharray = am_getlatestscores($db, 'none', 'list'); foreach ($higharray as $hhscore)
...try testing the $higharray variable...
It may be undefined, an empty string or FALSE.
|
|
|
|
|
Hey everybody,
I posted something simmilar while ago, but didn't received enough info.
What I am looking for is php script that would allow users to create an album, upload multiple files, store files itself on server, and data about them in database. what else Im looking is ability to create thumbnail at the same time when file is uploaded.
I was searching quite a lot and found this one: http://articles.sitepoint.com/article/php-gallery-system-minutes/1[^]
Basically it should do everything what I am looking for, but unfortunetely I am not able to implement it.
When I download source files from this tutorial, and upload them to my server, these doesnt do all the stuff. When I run preupload.php it seems that files are uploaded, and confirmation message appears, data is stored in one of the tables in database, but no files or thumbnails appears on server....
Any ideas? Am I missing something big in here or the tutorial is inncomplete?
If anybody knows any other tutorials that would do something like this one pls give me a link
Thank you in advance.
|
|
|
|
|
I ran across this a few years ago and found I could just handle the raw post data myself.
Recently I had to write a script to handle an ajax call, from grease monkey in fact, and the raw post data is there and the post variable is set but it is blank.
I would prefer to use the post variable instead of having to manually parse the data.
A sample html/js/php fragments of what I am doing follows:
<?php
fwrite($fp,file_get_contents("php://input"));
?>
I can read the raw post data.
But when I use something like
<?php
echo $_POST['name'];
?>
it is blank
My source data is built via js like this...
js...
var postvar = "name="+encodeURI(name)+"&markup="+encodeURI(markup)
...js
Name is a identifier and markup is a select html code.
I am curious if anyone has figured out why php fails to parse the raw data sent to a page.
|
|
|
|
|
cjoki wrote:
<?php
echo $_POST['name'];
?>
Try print_r( $_REQUEST ); to see what was sent. Without seeing the rest of your javascript I can only guess at what the problem is.
The most common problems are that the http request was opened with 'GET' rather than 'POST' eg.
http_request.open('POST',<br />
url, true);
Or the parameters weren't sent eg. http_request.send(postvar);
Or I may have missed the point, so please clarify.
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
fly904,
thanks for the response but I found my error. Using the GM_xmlhttpRequest object I mistakely set the content type to...
GM_xmlhttpRequest({
method: 'POST',
url: '[URL deleted for post]/copy_prdt.php',
data: postdata,
headers:
{
'Content-type': 'x-www-form-urlencoded'
},
onload: function(responseDetails)
{
alert('Request returned ' + responseDetails.status + ' ' + responseDetails.statusText + '\n\n' +' data:\n' + responseDetails.responseText);
},
onError: function(responseDetails)
{
alert('Request complained ' + responseDetails.status + ' ' + responseDetails.statusText + '\n\n' +' data:\n' + responseDetails.responseText);
}
});
and it needed to be...
GM_xmlhttpRequest({
method: 'POST',
url: '[URL deleted for post]/copy_prdt.php',
data: postdata,
headers:
{
'Content-type': 'application/x-www-form-urlencoded'
},
onload: function(responseDetails)
{
alert('Request returned ' + responseDetails.status + ' ' + responseDetails.statusText + '\n\n' +' data:\n' + responseDetails.responseText);
},
onError: function(responseDetails)
{
alert('Request complained ' + responseDetails.status + ' ' + responseDetails.statusText + '\n\n' +' data:\n' + responseDetails.responseText);
}
});
It is odd, I did not get any error messages and the script seem to work fine, except for the post variable not having the data parsed into it.
I can only guess that the php parser was confused and quietly aborted the parsing of the post data.
|
|
|
|
|
cjoki wrote: I can only guess that the php parser was confused and quietly aborted the parsing of the post data.
Debugging Ajax is a bitch, as it doesn't always throw an error, because technically it works although not the way you want it .
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
I tend to use an "output" box for this that just says what the code is doing step by step on js side and Firefox Error Console. But some errors do still seem to hide.
A function you may know: To read headers sent using PHP you can use:
<?php
var_dump(headers_list());
?>
|
|
|
|
|
var_dump prints the results to a browser. In an ajax based system this can be messy.
Although I could have used var_export, I instead used fwrite($fp,file_get_contents("php://input")); so to write the contents of the raw post data before the parser works on filling the $_POST array. Doing it this way allows the server side script of a ajax solution to continue and return some value so your javascript can shutdown gracefully while allowing you to capture the content.
I also use a firefox addon called httpfox so I can observe the communication between my browser and the server.
|
|
|
|
|
httpfox
Been looking for something like that for a while. Plain & Simple.
|
|
|
|
|
its good to share
|
|
|
|
|
Hello Sir
I have one linux source code ..i need to convert into windows , in code they are using assembly language but i am not a proficient in assembly language ..but i know one conversion need for running that assembly language into visual cpp compiler but i dont know how to do it ? please replay me sirs!!
This is my code snippet
static inline int mid_pred(int a, int b, int c)
{
int i=b;
__asm{
"cmp %2, %1 \n\t;"
"cmovg %1, %0 \n\t;"
"cmovg %2, %1 \n\t;"
"cmp %3, %1 \n\t;"
"cmovl %3, %1 \n\t;"
"cmp %1, %0 \n\t;"
"cmovg %1, %0 \n\t;"
:"+&r"(i), "+&r"(a)
:"r"(b), "r"(c)
};
return 0
}
</pre>
i am getting this errors in the above source code
<code>
error C2400: inline assembler syntax error in 'opcode'; found 'bad token'
error C2400: inline assembler syntax error in 'opcode'; found 'bad token'
error C2400: inline assembler syntax error in 'opcode'; found 'bad token'
error C2400: inline assembler syntax error in 'opcode'; found 'bad token'
error C2400: inline assembler syntax error in 'opcode'; found 'bad token'
error C2400: inline assembler syntax error in 'opcode'; found 'bad token'
error C2400: inline assembler syntax error in 'opcode'; found ':'
error C2400: inline assembler syntax error in 'opcode'; found ':'
</code>
please Respond me Sirs
Thanks!
<div class="ForumSig"><font face="Verdana, Arial" size="2" color="#990033">Raju !!!</font>
</div>
|
|
|
|
|
I don't know much about Visual CPP but the messages look like they are saying that it does not recognise the code in the __asm block. I must say the syntax looks like it needs some sort of preprocessing before going into the compile phase. Have you checked the documentation for the proper format of embedded assembler operations?
|
|
|
|
|
Might help
I would recommend posting this in C/C++ forum, as you will get more help there.
|
|
|
|
|
Hello everyone, i have a big problem with this $smarty->assign
I found a nice script that would add smileys to my website in users comments but since the comments are coming from the database i am not sure how to make smarty replace the smiley characters with images.
Here is the script i am trying to get working:
function addSmilies($text) {
$codesToConvert = array(
':)' => '<img src="http://blog.sachinkraj.com/images/smilies/smile.png" alt="smile" />',
':-)' => '<img src="http://blog.sachinkraj.com/images/smilies/smile.png" alt="smile" />',
':D' => '<img src="http://blog.sachinkraj.com/images/smilies/laugh.png" alt="laugh" />',
':d' => '<img src="http://blog.sachinkraj.com/images/smilies/laugh.png" alt="laugh" />',
';)' => '<img src="http://blog.sachinkraj.com/images/smilies/wink.png" alt="wink" />',
':P' => '<img src="http://blog.sachinkraj.com/images/smilies/tounge.png" alt="tounge" />',
':-P' => '<img src="http://blog.sachinkraj.com/images/smilies/tounge.png" alt="tounge" />',
':-p' => '<img src="http://blog.sachinkraj.com/images/smilies/tounge.png" alt="tounge" />',
':p' => '<img src="http://blog.sachinkraj.com/images/smilies/tounge.png" alt="tounge" />',
':(' => '<img src="http://blog.sachinkraj.com/images/smilies/sad.png" alt="sad face" />',
':o' => '<img src="http://blog.sachinkraj.com/images/smilies/shock.png" alt="shock" />',
':O' => '<img src="http://blog.sachinkraj.com/images/smilies/shock.png" alt="shock" />',
':0' => '<img src="http://blog.sachinkraj.com/images/smilies/shock.png" alt="shock" />',
':|' => '<img src="http://blog.sachinkraj.com/images/smilies/straight.png" alt="straight face" />',
':-|' => '<img src="http://blog.sachinkraj.com/images/smilies/straight.png" alt="straight face" />'
);
return (strtr($text, $codesToConvert));
}
Here is how the above code works:
$comment = 'This is the example comment with few smilies code we use normally. Like these: :) :D :P :p :O :-| . Its funny and cute. Isnt it? :)';
echo '<strong>Text with smiley codes:</strong>' . $comment ;
echo '<strong>Text with smiley images:</strong>' . addSmilies($comment);
Here is part of the code that assigns the smarty variable which are later used to display the reviews (comments).
$averageRating = am_getrating($got_gameid);
$reviews = am_queries($db, "SELECT * FROM AMCMS_reviews WHERE gameid=$got_gameid AND approved=1;");
$countreviews = am_countrecords($db, "SELECT * FROM AMCMS_reviews WHERE gameid=$got_gameid AND approved=1;");
$smarty->assign('sitetitle',$sitetitle);
$smarty->assign('metadesc',$metadesc);
$smarty->assign('metakeywords',$metakeywords);
$smarty->assign('insertGame',$insertGame);
$smarty->assign('headload',$headload);
$smarty->assign('bodyload',$bodyload);
$smarty->assign('gameAvgRating', $averageRating);
$smarty->assign('echoComment', $echoComment);
$smarty->assign('gameId', $gameres[0][0]);
$smarty->assign('gameName', $gameres[0][1]);
$smarty->assign('gameDescription', $gameres[0][2]);
$smarty->assign('gameOriginalWidth', $originalwidth);
$smarty->assign('gameOriginalHeight', $originalheight);
$smarty->assign('gameFilename', $gameres[0][6]);
$smarty->assign('gameCategory', $gameres[0][7]);
$smarty->assign('gamePlayCount', $gameres[0][8]);
$smarty->assign('gameExtension', strtolower($gameres[0][10]));
$smarty->assign('gameReviews', $reviews);
$smarty->assign('gameCountReviews', $countreviews);
$smarty->assign('gameHighScoreList', am_highscore($gameres[0][0], 'high', 10, 'list', false));
$smarty->assign('gameRecommendedList', am_listnewgames('list', 8, $gameres[0][7], false));
$smarty->assign('gameCode', html_entity_decode($gameres[0][15]));
Here is the code that shows the comments
{$echoComment}
</div></div>
<p />
<div class="reviews">
<h2 class="title"><center>{$gameCountReviews} reviews for {$gameName}</center></h2>
<center>
{foreach from=$gameReviews item=individualReview}
<div class="individualreview">Review by <i>{$individualReview.2}</i><p />
<div class="reviewtext">{$individualReview.3}</div>
</div><br /><p />
{/foreach}
I have been trying to fix this all day and it just wont show the comments, i tried to assign the script to a smarty variable but then how would i use it as the script says ? addSmilies($comment);
I tried few other scripts and tried to include it in the .tpl file but that didnt work, i tried all kinds of ways to make the addSmilies({$individualReview.3}) work by adding what not in there but it just wont work.
For the last few hours i have been looking in the smarty manual but i cant see anything even close to this
I am sorry for all the code and i am really new to php and smarty so i really need some help.
Please somebody help me
|
|
|
|
|
The easiest way would be to add them before sending them to the template.
$reviews = am_queries($db, "SELECT * FROM AMCMS_reviews WHERE gameid=$got_gameid AND approved=1;");
foreach ( $reviews as $rev )
{
$rev[ 3 ] = addSmilies( $rev[ 3 ] );
}
$smarty->assign('gameReviews', $reviews);
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
I tried what you suggested but the script crashed so i changed it to this script:
function smiley($text)
{
$path = "./smiley";
$width = '24';
$height = '24';
$arr[":))"] = "d.png";
$arr[":(("] = "cry.png";
$arr[";)"] = "wink.png";
$arr[":s"] = "s.png";
$arr[":@"] = "angry.png";
$arr[":)"] = "happy.png";
$arr[":("] = "sad.png";
$arr[":o"] = "o.png";
$arr[":x"] = "love.png";
$arr["b-)"] = "b.png";
$arr[":d"] = "d.png";
$arr[":p"] = "p.png";
$arr["o)"] = "angel.png";
$arr[":-b"] = "nerd.png";
$arr[":*"] = "kiss.png";
$arr["x("] = "angry.png";
$code_arr = array_keys($arr);
foreach($code_arr as $code)
$text = str_ireplace($code, "<img width = '" . $width . "' height = '" . $height . "' src='$path/" . $arr[$code] . "'>" , $text);
return $text;
}
After putting your code in the file nothing changed all smilies just show as text
$reviews = am_queries($db, "SELECT * FROM AMCMS_reviews WHERE gameid=$got_gameid AND approved=1;");
foreach ( $reviews as $rev )
{
$rev[ 3 ] = smiley( $rev[ 3 ] );
}
Any other suggestions ?
Any way to do the same foreach in smarty ?
Thanks for helping btw
|
|
|
|
|
My bad.
I would use your previous addSmilies method (strtr). It is alot more efficient.
I was a bit of a clot and forgot that the value $rev from the foreach wasn't a pointer to $reviews . A normal for loop will work.
$reviews = am_queries($db, "SELECT * FROM AMCMS_reviews WHERE gameid=$got_gameid AND approved=1;");
for ( $i = 0; $i < count( $reviews ); $i++ )
{
$reviews[ $i ][ 3 ] = addSmilies( $reviews[ $i ][ 3 ] );
}
djkee wrote: Any way to do the same foreach in smarty ?
There is no point, as it shouldn't technically be in the template. And it would make the template messy, which is never a good thing.
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
This is awesome Thank you so much for the help
It works like a charm
|
|
|
|
|