bertrc Posted November 22, 2022 Share Posted November 22, 2022 printf error line <?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqli = mysqli_connect("localhost", "root", "P-11fl32fg14", "cocoa"); $query = "SELECT type_chocolate.type_chocolate,type_chocolate.type_chocolate FROM type_chocolate"; $result = mysqli_query($mysqli, $query); /* numeric array */ while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) { printf("%s %s\n","<a href='cacau_type_chocolate.php?type_chocolate=" . $row['type_chocolate'] . ">,". $row['type_chocolate'] . "</a>");?> <br> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/315573-fatal-error-uncaught-argumentcounterror-3-arguments-are-required-2-given-in-varwwwhtmlcocoaindexphp13-stack-trace-0-varwwwhtmlcocoaindexphp13-printfs-sn/ Share on other sites More sharing options...
Barand Posted November 22, 2022 Share Posted November 22, 2022 https://www.php.net/print_f You don't need to select the same column twice. The %s in the print_f format argument are placeholders for the string variables ($row['type_chocolate']) mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqli = mysqli_connect("localhost", "root", "P-11fl32fg14", "cocoa"); $query = "SELECT type_chocolate FROM type_chocolate"; $result = mysqli_query($mysqli, $query); while ($row = mysqli_fetch_assoc($result)) { printf("<a href='cacau_type_chocolate.php?type_chocolate=%s'>%s</a>", $row['type_chocolate'], $row['type_chocolate']); } 1 Quote Link to comment https://forums.phpfreaks.com/topic/315573-fatal-error-uncaught-argumentcounterror-3-arguments-are-required-2-given-in-varwwwhtmlcocoaindexphp13-stack-trace-0-varwwwhtmlcocoaindexphp13-printfs-sn/#findComment-1602876 Share on other sites More sharing options...
bertrc Posted November 22, 2022 Author Share Posted November 22, 2022 it works printf("%s %s\n","<a href='cacau_tipus_xocolata.php?tipus_xocolata=" . $row["tipus_xocolata"] . "'>" , $row["tipus_xocolata"] . "</a>");?> <br> Quote Link to comment https://forums.phpfreaks.com/topic/315573-fatal-error-uncaught-argumentcounterror-3-arguments-are-required-2-given-in-varwwwhtmlcocoaindexphp13-stack-trace-0-varwwwhtmlcocoaindexphp13-printfs-sn/#findComment-1602878 Share on other sites More sharing options...
Barand Posted November 22, 2022 Share Posted November 22, 2022 Probably the wierdest (and worst) way of using printf that I have ever seen. Quote Link to comment https://forums.phpfreaks.com/topic/315573-fatal-error-uncaught-argumentcounterror-3-arguments-are-required-2-given-in-varwwwhtmlcocoaindexphp13-stack-trace-0-varwwwhtmlcocoaindexphp13-printfs-sn/#findComment-1602879 Share on other sites More sharing options...
Phi11W Posted November 23, 2022 Share Posted November 23, 2022 Or even, delving a little deeper into the Documentation: printf( '<a href="cacau_type_chocolate.php?type_chocolate=%1$s">%1$s</a>', $row[ 'type_chocolate' ] ); Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/315573-fatal-error-uncaught-argumentcounterror-3-arguments-are-required-2-given-in-varwwwhtmlcocoaindexphp13-stack-trace-0-varwwwhtmlcocoaindexphp13-printfs-sn/#findComment-1602901 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.