Jump to content

My life have ended help please


Go to solution Solved by maxxd,

Recommended Posts

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 by alexandre
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

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 by ginerjm
  • Like 1
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.

  • Like 1

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

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 by ginerjm
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 by alexandre

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.

  • Like 1

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 😪

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

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

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.