Jump to content

Recommended Posts

I have two files index.php and cocoa_type_chocolate.php

I have 1 links is dark chocolate.

I want one query when I press one link 

index.php

<a href='cocoa_type_chocolate.php?type_chocolate=dark'>Dark</a>

cocoa_type_chocolate.php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqli = mysqli_connect("localhost", "root", "*****", "cocoa"); $query = "SELECT chocolate.id_chocolate,chocolate.name_chocolate,type_chocolate.id_type_chocolate, type_chocolate.type_chocolate ,type_chocolate.id_chocolate FROM chocolate INNER JOIN type_chocolate ON chocolate.id_chocolate =type_chocolate.id_type_chocolate WHERE type_chocolate='dark'"; $result = mysqli_query($mysqli, $query); /* numeric array */ while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) { printf("%s %s %s %s %s\n", $row["id_chocolate"], $row["name_chocolate"], $row["id_type_chocolate"],$row["type_chocolate"],$row["id_chocolate"]);?> <br> <?php } ?>

 

Edited by bertrc
Link to comment
https://forums.phpfreaks.com/topic/315563-_get-in-query-mysql-in-condicion-where/
Share on other sites

 have two files index.php and cocoa_type_chocolate.php

I have 1 links is dark chocolate.

I want one query when I press one link 

index.php

<a href='cocoa_type_chocolate.php?type_chocolate=dark'>Dark</a>

cocoa_type_chocolate.php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$mysqli = mysqli_connect("localhost", "root", "*****", "cocoa");

$query = "SELECT chocolate.id_chocolate,chocolate.name_chocolate,type_chocolate.id_type_chocolate, type_chocolate.type_chocolate ,type_chocolate.id_chocolate

FROM chocolate INNER JOIN type_chocolate ON chocolate.id_chocolate =type_chocolate.id_type_chocolate

WHERE type_chocolate='dark'";

$result = mysqli_query($mysqli, $query);

/* numeric array */

while ($row = mysqli_fetch_array($result, MYSQLI_BOTH))

{ printf("%s %s %s %s %s\n", $row["id_chocolate"], $row["name_chocolate"], $row["id_type_chocolate"],$row["type_chocolate"],$row["id_chocolate"]);?> <br> <?php } ?>

 

Edited 13 hours ago by bertrc

 I have two files index.php and cocoa_type_chocolate.php.

I have 1 links is dark chocolate.

I want one query when I press one link. 

I want to change  the condition where, to change between 3 chocolates milk, dark, and white.

in the condicion where I should use get.

but I have problem with the url and where condicion.

index.php

<a href='cocoa_type_chocolate.php?type_chocolate=dark'>Dark</a>

cocoa_type_chocolate.php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$mysqli = mysqli_connect("localhost", "root", "*****", "cocoa");

$query = "SELECT chocolate.id_chocolate,chocolate.name_chocolate,type_chocolate.id_type_chocolate, type_chocolate.type_chocolate ,type_chocolate.id_chocolate

FROM chocolate

INNER JOIN

type_chocolate

ON chocolate.id_chocolate =type_chocolate.id_type_chocolate

WHERE type_chocolate='dark'";

$result = mysqli_query($mysqli, $query);

/* numeric array */

while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {

printf("%s %s %s %s %s\n", $row["id_chocolate"], $row["name_chocolate"], $row["id_type_chocolate"],$row["type_chocolate"],$row["id_chocolate"]);

?> <br> <?php } ?>

 

It is working

thank you

index.php

<a href='cocoa_type_chocolate.php?type_chocolate=dark'>Dark</a>

<a href='cocoa_type_chocolate.php?type_chocolate=milk'>Milk</a>

<a href='cocoa_type_chocolate.php?type_chocolate=white'>White</a>

cocoa_type_chocolate.php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$mysqli = mysqli_connect("localhost", "root", "*****", "cocoa");

$query = "SELECT chocolate.id_chocolate,chocolate.name_chocolate,type_chocolate.id_type_chocolate, type_chocolate.type_chocolate ,type_chocolate.id_chocolate

FROM chocolate

INNER JOIN

type_chocolate

ON chocolate.id_chocolate =type_chocolate.id_type_chocolate

WHERE type_chocolate='$_GET[type_chocolate]'";

$result = mysqli_query($mysqli, $query);

/* numeric array */

while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {

printf("%s %s %s %s %s\n", $row["id_chocolate"], $row["name_chocolate"], $row["id_type_chocolate"],$row["type_chocolate"],$row["id_chocolate"]);

?>

<br>

<?php } ?>

 

Edited by bertrc
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.