Jump to content

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


bertrc
 Share

Recommended Posts

I have two files index.php and cocoa_type_chocolate.php

I have 3 links are dark, milk, white chocolate.

I want one query when I press one link but I don't now if I need to use if , else if else if.

 

index.php

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

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

<a href="cocoa_type_chocolate.php?type_chocolate=milk">Milk</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 } ?>

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='milk'"; $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 } ?>

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='white'"; $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 } ?>

Link to comment
Share on other sites

New Members

 2

Posted just now

I have two files index.php and cocoa_type_chocolate.php

I have 3 links are dark, milk, white chocolate.

I want one query when I press one link but I don't know if I need to use if , else if else if.

 

index.php

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

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

<a href="cocoa_type_chocolate.php?type_chocolate=milk">Milk</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 } ?>

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='milk'"; $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 } ?>

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='white'"; $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 } ?>

 

Link to comment
Share on other sites

I have two files index.php and cocoa_type_chocolate.php

I have 3 links are dark, milk, white chocolate.

I want one query when I press dark, another query when I press white, and another one when I press milk,  but I don't know if I need to use if , else if else if.

with method get or post

index.php

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

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

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

 

cocoa_type_chocolate.php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqli = mysqli_connect("localhost", "root", "P-11fl32fg14", "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 } ?>

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqli = mysqli_connect("localhost", "root", "P-11fl32fg14", "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='milk'"; $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 } ?>

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqli = mysqli_connect("localhost", "root", "P-11fl32fg14", "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='white'"; $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 } ?>

 

Link to comment
Share on other sites

try this for cocoa_type_chocolate.php

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); 
$mysqli = mysqli_connect("localhost", "root", "*****", "cocoa");

if (isset($_GET['type_chocolate'])) {
    $res = $mysqli->prepare("SELECT c.id_chocolate
                                  , c.name_chocolate
                                  , t.id_type_chocolate
                                  , t.type_chocolate 
                             FROM chocolate c
                                  INNER JOIN type_chocolate t ON c.id_chocolate = t.id_type_chocolate 
                             WHERE type_chocolate = ?
                             ");
    $res->bind_param('s', $_GET['type_chocolate']);
    $res->execute();
    $res->bind_result($id_chocolate, $name_chocolate, $id_type_chocolate, $type_chocolate) ;
    
    echo '<pre>';
    while ($res->fetch()) {
        printf("%s %s %s %s\n", $id_chocolate, $name_chocolate, $id_type_chocolate, $type_chocolate);
    }
    echo '</pre>';
} 

PS not sure if the join is right as I don't know your table structure

 

edit - forgot the execute (I hate mysqli - too many things to do. Give me PDO any day)

Link to comment
Share on other sites

Parse error: syntax error, unexpected token "<", expecting end of file in /var/www/html/cacao/cacao_type_chocolate.php on line 8

I am beginer with php and my english is not very good

I am catalan

I have one error,

thank you

How to put the get in the sentence where dark

$query = "SELECT xocolata.id_xocolata,xocolata.nom_xocolata,tipus_xocolata.id_tipus_xocolata, tipus_xocolata.tipus_xocolata ,tipus_xocolata.id_xocolata FROM xocolata INNER JOIN tipus_xocolata ON xocolata.id_xocolata =tipus_xocolata.id_tipus_xocolata WHERE tipus_xocolata='dark'";

I don't know php oriented objects

I have the database in catalan,  I translate in english

Edited by bertrc
Link to comment
Share on other sites

arse error: syntax error, unexpected token "<", expecting end of file in /var/www/html/cacao/cacao_type_chocolate.php on line 8

I am beginer with php and my english is not very good

I am catalan

I have one error,

thank you

How to put the get in the sentence where dark

$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'";

don't know php oriented objects

I have the database in catalan,  I translate in english

Link to comment
Share on other sites

<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$mysqli = mysqli_connect("localhost", "root", "P-11fl32fg14", "cacau");



if (isset($_GET['tipus_xocolata'])) {

$res = $mysqli->prepare("SELECT c.id_xocolata

, c.nom_xocolata

, t.id_tipus_xocolata

, t.tipus_xocolata

FROM xocolata c

INNER JOIN tipus_xocolata t ON c.id_xocolata = t.id_tipus_xocolata

WHERE tipus_xocolata = ?

");

$res->bind_param('s', $_GET['tipus_xocolata']);

$res->bid_result($id_xocolata, $nom_xocolata, $id_tipus_xocolata, $tipus_xocolata) ;

echo '<pre>';

while ($res->fetch()) {

printf("%s %s %s %s\n", $id_xocolata, $nom_xocolata, $id_tipus_xocolata, $tipus_xocolata);

}

echo '</pre>';

}

?>
Parse error: syntax error, unexpected token "<", expecting end of file in /var/www/html/cacau/cacau_tipus_xocolata.php on line 6

 

Edited by bertrc
Link to comment
Share on other sites

I edited my code just after posting but you evidently were quick off the mark and missed the changes in your copy.

$res->bind_param('s', $_GET['tipus_xocolata']);

$res->bid_result($id_xocolata, $nom_xocolata, $id_tipus_xocolata, $tipus_xocolata) ;

was changed to

$res->bind_param('s', $_GET['tipus_xocolata']);
$res->execute();                                                                               // added
$res->bind_result($id_xocolata, $nom_xocolata, $id_tipus_xocolata, $tipus_xocolata) ;          // changed bid_result to bind_result

But I don't see where the "<" is coming from.

Unexpected end-of-file is usually the result of a missing end "}" or unclosed quotes.

* * * * * *

As for the where... 'dark', that's done by the placeholder "?" in the query and the bind_param to replace the placeholder with the value when the query is executed

image.png.0b829531b78036e382f06d180d335274.png

Link to comment
Share on other sites

23 hours ago, bertrc said:

mysqli_connect("localhost", "root", "*****", ...

DO NOT use the root user for Applications. 
ALWAYS create a dedicated account for each Application and grant that account the correct privileges in the database. 

Why?  You should always keep the biggest and best tools in the toolbox for yourself, because it will be you cleaning up the mess made by other people and processes. 

Regards, 
   Phill  W.

 

Link to comment
Share on other sites

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.

 Share

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