Hi,
I’m trying to code a book browser with a database backend using HTML, phpMyAdmin, and mySQL. Right now the search function creates a list of book titles with hyperlinks leading to individual blank pages. What I want to make happen is somehow transfer the basic information of said books from Wikipedia pages, to the corresponding blank pages created, when the hyperlinks are clicked. My current code is below: if it helps, the hyperlinks are created at the very end of the code. Please help.
– tristanwang99
<?php if (isset($_GET['q'])) { $q = $_GET['q']; } $con = mysqli_connect('localhost','root','1shoeinthesock','panoply_test'); ?><head>
<title>PANOPLY BETA</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript">
</script>
<style>
.container1 {
position: absolute;
top: 40%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}
.container2 {
top: 0;
transform: translateY(-50%);
}
body {
font-family: times;
}
h3 {
margin: 20px 0px 0px 0px;
padding: 0;
}
p {
margin: 0;
padding: 0;
}
a {
color: #000000;
text-decoration: underline;
}
a:hover {
color: #000000;
text-decoration: none;
}
</style>
</head>
<body>
<div class = "container1" align = "center">
<font size="36">PANOPLY</font><br><br>
<form action="index.php" method="GET" id="searchForm" />
<input type="text" id="searchBar" name="q" placeholder="search for books..." maxlength="25" autocomplete="off" onMouseDown="" onBlur="" /><input type="submit" id="searchBtn" name="search" value="Go" /><br><br>
</form>
</div>
<?php
if(!isset($q)) {
echo '';
} else {
$keyword = strtok($q, " ");
$predicate_word = "";
$predicate_condition = "";
while ($keyword) {
$condition = "";
switch ($keyword) {
case "COMPLEX":
$condition = "`COMPLEX?` = 1";
break;
case "CONVERSATIONAL":
$condition = "`CONVERSATIONAL?` = 1";
break;
case "GLOOMY":
$condition = "`GLOOMY?` = 1";
break;
case "HEARTWRENCHING":
$condition = "`HEARTWRENCHING?` = 1";
break;
case "INFORMATIVE":
$condition = "`INFORMATIVE?` = 1";
break;
case "METAPHORICAL":
$condition = "`METAPHORICAL?` = 1";
break;
case "RIVETING":
$condition = "`RIVETING?` = 1";
break;
case "SURREAL":
$condition = "`SURREAL?` = 1";
break;
case "UNEXPECTED":
$condition = "`UNEXPECTED?` = 1";
break;
case "UPLIFTING":
$condition = "`UPLIFTING?` = 1";
break;
case "SENTIMENTAL":
$condition = "`SENTIMENTAL?` = 1";
break;
case "SPINETINGLING":
$condition = "`SPINETINGLING?` = 1";
break;
case "WITTY":
$condition = "`WITTY?` = 1";
break;
}
if ($condition == "") {
if ($predicate_word == "") {
$predicate_word = $keyword;
} else {
$predicate_word = $predicate_word." ".$keyword;
}
} else {
if ($predicate_condition == "") {
$predicate_condition = $condition;
} else {
$predicate_condition = $predicate_condition." AND ".$condition;
}
}
$keyword = strtok(" ");
}
$query_string = "SELECT * FROM `TABLE 1` WHERE ";
if ($predicate_condition) {
$query_string = $query_string.$predicate_condition;
}
if ($predicate_word) {
if ($predicate_condition) {
$query_string = $query_string." AND ";
}
$query_string = $query_string."CONCAT(`TITLE`,`AUTHOR`,`GENRE`) LIKE '%".$predicate_word."%'";
}
echo '<BR>'.$query_string.'<BR>';
$query = mysqli_query($con, $query_string);
$num_rows = mysqli_num_rows($query);
?>
<p><strong><?php echo $num_rows; ?></strong> results for '<?php echo $q; ?>'</p>
<?php
while(isset($q) && ($row = mysqli_fetch_array($query))) {
$title = $row['TITLE'];
$author = $row['AUTHOR'];
$genre = $row['GENRE'];
echo '<h3><a href="' . $title . '.php">' . $title . '</h3></a><p> by ' . $author . '. ' . $genre . '. </p><br />';
}
}
?>
</body>