ginerjm Posted September 5, 2022 Share Posted September 5, 2022 Look very closely at what you typed for your query call. What is $sql? Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600161 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 yes i forgot that i changed the deprecated query form to a prepared query so i didnt change $sql for $stmt Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600162 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 Are you in the process of switching from Mysql to Mysqli? That's too bad IMHO. PDO is a much simpler way of doing db work and easier to use. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600163 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) no i didnt mean to say deprecated but just to change the syntax of the sample i use as structure. i just started in php. but i do like the synthax of this format. i saw some example of the pdo extension and for my understanding i chose this. it is more of a personal choice Edited September 5, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600164 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 20 minutes ago, ginerjm said: Are you in the process of switching from Mysql to Mysqli? That's too bad IMHO. PDO is a much simpler way of doing db work and easier to use. $stmt = $con->prepare('SELECT participationid, usernames, totaldonated FROM donationclashdetails GROUP BY participationid ORDER BY totaldonated DESC'); $result = mysqli_query($con, $stmt); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { //rankings echo ''. $row['participationid'] . $row['usernames'] . $row['donationamount']. ' - ' . ' - ' . '<br>'; } } is this possible that this query cant return a string or something .. i am getting this error. Fatal error: Uncaught TypeError: mysqli_query(): Argument #2 ($query) must be of type string, mysqli_stmt given in C:\xampp\htdocs\container\donation-clash\donation-clash.php:101 Stack trace: #0 C:\xampp\htdocs\container\donation-clash\donation-clash.php(101): mysqli_query(Object(mysqli), Object(mysqli_stmt)) #1 {main} thrown in C:\xampp\htdocs\container\donation-clash\donation-clash.php on line 101 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600168 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 (edited) I don't use mysqli so I can't answer that. You will have to read the php manual to see how a prepared statement is used. https://www.php.net/manual/en/mysqli-stmt.prepare.php Read the example for 'Procedural style' BTW - since you are not using any user-supplied arguments in your query, you really don't need to 'prepare' the query. Edited September 5, 2022 by ginerjm 1 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600169 Share on other sites More sharing options...
Barand Posted September 5, 2022 Share Posted September 5, 2022 19 minutes ago, alexandre said: $stmt = $con->prepare('SELECT participationid, usernames, totaldonated FROM donationclashdetails GROUP BY participationid ORDER BY totaldonated DESC'); $result = mysqli_query($con, $stmt); mysqli_query uses an SQL query (string) for its second argument. You are passing $stmt which is a prepared statement object. There is nothing in that query that needs preparing so just use mysqli_query with the query string. 1 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600170 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 new challenge for you guys $stmt = ('SELECT sum(totalpifcoincollected) FROM donationclashdetails'); $result = mysqli_query($con, $stmt); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { //displaying the total amount of pifcoin collected by participants for the week echo "the total collected this week for the donation clash:"; echo ''. ' - ' . ' - ' . ' - ' . ' - ' . $row['totalpifcoincollected']. '<br>'; } whatever i do i cant seem to be able to get past this undefined array error . it might be with the comma or placement i am not sure of what to put in the beginining of echo $rows Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600172 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 (edited) Why don't you look at the query I gave you and see how to do the sum and then try it again. OR do this: $stmt = ('SELECT sum(totalpifcoincollected) AS tot FROM donationclashdetails'); $result = mysqli_query($con, $stmt); while($row = mysqli_fetch_assoc($result)) { //displaying the total amount of pifcoin collected by participants for the week echo "the total collected this week for the donation clash: - - - - {$row['tot']}<br>"; } Edited September 5, 2022 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600173 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) 6 minutes ago, ginerjm said: Why don't you look at the query I gave you and see how to do the sum and then try it again. it is ok i removed it but now i am not sure if i can do this here $stmt = $con->prepare('SELECT * FROM donationclashdetails GROUP BY participationid ORDER BY totaldonated LIMIT(1000,0) DESC'); i am getting this Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(1000,0) DESC' at line 1 in C:\xampp\htdocs\container\donation-clash\donation-clash.php:126 Stack trace: #0 C:\xampp\htdocs\container\donation-clash\donation-clash.php(126): mysqli->prepare('SELECT * FROM d...') #1 {main} thrown in C:\xampp\htdocs\container\donation-clash\donation-clash.php on line 126 Edited September 5, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600174 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 I think it is time to begin a new topic since you are moving from point to point constantly. This latest query looks nothing like the ones we have helped you with all day and is totally wrong. Again - you don't have to prepare if not using any parameters in the query you only need a group by when you are doing arithmetic functions in the query And the DESC is part of the order by clause, not the limit clause. 1 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600175 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 yes i was thinking about starting a topic simply called web development questions. and i know i am doing things differently it is just that i was testing lots of combinaisons without it working but i think i just understood a bit better now. but do the * after the select is wrong too because i still need to pull all the data from 1000 rows and display it as ranking page.. i will have lots of research ahead 😪 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600176 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 31 minutes ago, ginerjm said: I think it is time to begin a new topic since you are moving from point to point constantly. This latest query looks nothing like the ones we have helped you with all day and is totally wrong. Again - you don't have to prepare if not using any parameters in the query you only need a group by when you are doing arithmetic functions in the query And the DESC is part of the order by clause, not the limit clause. select participationid, sum(donationamount) as total_donated from donationclashdetails group by participationid order by total_donated desc so here where should i put the limit and numbers for it to actualy work without me getting synthax error beacuse i cant seem to be able to make it work Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600177 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 Have you read any manuals to answer these questions for you? How about the mysql manual? google it! We are here for people who are having problems but not when they cannot be bothered to do their own research before turning to us for help. Read A Book. https://www.w3schools.com/mysql/mysql_select.asp Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600178 Share on other sites More sharing options...
alexandre Posted September 6, 2022 Author Share Posted September 6, 2022 i have literally 50 tabs opened in my browser if you think i am not doing researches .. you are wrong . if i ask is because i cant find the exact answer in the manual they explain extremely bad and gives barely a couple examples that doesnt match what i need to know. maybe this answer i could have googled it but you was here answering me so i simply prefferred to enjoy some more accurate advices than digging in google. sorry if i bothered you this wont happen again. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/3/#findComment-1600179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.