/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Getting Data from two tables

I have two tables on my database, one called comics, and one called subjects.

I’m trying to get data from both tables, but I’m running into an error.

Here’s my code:

[code=php]<?php
include (‘../inserts/comic_db.php’);

# Set up variables
$subject= @mysql_real_escape_string(htmlspecialchars($_GET[‘subject’]));

if(!$comics = mysql_query(“SELECT * FROM comics WHERE Keywords LIKE (‘%$subject%’)”)){
echo “<br>Error with MySQL:<br>”.mysql_error();
}
if(!$description = mysql_query(“SELECT * FROM subjects WHERE `Keyword` LIKE (‘$subject’)”)){
echo “<br>Error with MySQL:<br>”.mysql_error();
}

$nl = “n”;
$comic_list = ”;
if (empty($_GET[‘page’]))
{
$page=1;
}
else
{
$page=$_GET[‘page’];
}
$next=$page+1;
$previous=$page-1;
// debug
$num = @mysql_num_rows($comics);
$comic_array=array();
$counter=1;
while($row=mysql_fetch_array($comics))
{
$comic_array[$counter] = ‘<li><a href=”./chronological.php?comic=’.$row[‘Number’].'”><img src=”../comics/sem_’.$row[‘Semester’].’/’.$row[‘Comic’].'”></a></li>’.$nl.”;
$counter+=1;
}

$row2=msql_fetch_array($description);
$describe=$row2[‘Description’];
//Create the page here.

include(“../inserts/head.htm”);
echo (‘
<link type=”text/css” rel=”stylesheet” href=”../CSS/setup.css”>
<link type=”text/css” rel=”stylesheet” href=”../CSS/comic.css”>
<title>’.$subject.'</title>
</head>
<body>
<h1>’.$subject.'</h1>
<h2>’.$describe.'</h2>
<ul class=”comic”>
‘);
$comic_end=$page*5;
$comic_start=$comic_end-4;
for ($comic_count=$comic_start; $comic_count<=$comic_end;$comic_count++)
{
echo $comic_array[$comic_count];
}
echo (‘</ul>
‘);

# previous/next stuff
echo (‘<ul id=”nav”>
‘);
if ($page>1)
{
echo(‘<li><a href=”./subjects-exp.php?subject=’.$subject.’&page=’.$previous.'”>Previous</a></li>’);
}
echo (‘<li><a href=”../subjects.php”>Subjects</a></li>
<li><a href=”../index.php”>Back To Main</a></li>
‘);
if (!empty($comic_array[$comic_count]))
{
echo(‘<li><a href=”./subjects-exp.php?subject=’.$subject.’&page=’.$next.'”>Next</a></li>’);
}
?>
</ul>
</body>
</html>[/code]

The result is a blank page. I’m sure the error is in

[code]$row2=msql_fetch_array($description);
$describe=$row2[‘Description’];[/code]

since when I comment those out, a working page does show up, albeit without some of the data I want in there (namely that from the table ‘subjects’).

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@The_Little_GuyOct 22.2006 — What's the error?
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorOct 22.2006 — If I knew, I'd fix it! I posted this with the hopes someone could tell me what I'm doing wrong. All I'm getting is a blank page.
Copy linkTweet thisAlerts:
@The_Little_GuyOct 22.2006 — Maybe try this:
[code=php]<?php
include ('../inserts/comic_db.php');

# Set up variables
$subject= @mysql_real_escape_string(htmlspecialchars($_GET['subject']));
$comics = mysql_query("SELECT * FROM comics WHERE Keywords LIKE ('%$subject%')")or die(mysql_error());
$description = mysql_query("SELECT * FROM subjects WHERE Keyword LIKE ('$subject')")or die(mysql_error());

$nl = "n";
$comic_list = '';
if (empty($_GET['page']))
{
$page=1;
}
else
{
$page=$_GET['page'];
}
$next=$page+1;
$previous=$page-1;
// debug
$num = @mysql_num_rows($comics);
$comic_array=array();
$counter=1;
while($row=mysql_fetch_array($comics))
{
$comic_array[$counter] = '<li><a href="./chronological.php?comic='.$row['Number'].'"><img src="../comics/sem_'.$row['Semester'].'/'.$row['Comic'].'"></a></li>'.$nl.'';
$counter+=1;
}

$row2=msql_fetch_array($description);
$describe=$row2['Description'];
//Create the page here.

include("../inserts/head.htm");
echo ('
<link type="text/css" rel="stylesheet" href="../CSS/setup.css">
<link type="text/css" rel="stylesheet" href="../CSS/comic.css">
<title>'.$subject.'</title>
</head>
<body>
<h1>'.$subject.'</h1>
<h2>'.$describe.'</h2>
<ul class="comic">
');
$comic_end=$page*5;
$comic_start=$comic_end-4;
for ($comic_count=$comic_start; $comic_count<=$comic_end;$comic_count++)
{
echo $comic_array[$comic_count];
}
echo ('</ul>
');

# previous/next stuff
echo ('<ul id="nav">
');
if ($page>1)
{
echo('<li><a href="./subjects-exp.php?subject='.$subject.'&page='.$previous.'">Previous</a></li>');
}
echo ('<li><a href="../subjects.php">Subjects</a></li>
<li><a href="../index.php">Back To Main</a></li>
');
if (!empty($comic_array[$comic_count]))
{
echo('<li><a href="./subjects-exp.php?subject='.$subject.'&page='.$next.'">Next</a></li>');
}
?>
</ul>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorOct 22.2006 — The result is a completely blank page. I copy and pasted directly.
Copy linkTweet thisAlerts:
@The_Little_GuyOct 22.2006 — $row2=msql_fetch_array($description);

shouldn't it be [B]mysql_fetch_array[/B]?
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorOct 22.2006 — There we go. One last question: What in furnation does MSQL stand for? Because it seems to be a keyword.
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorOct 22.2006 — Oh, okay. Thanks.
Copy linkTweet thisAlerts:
@pcthugOct 22.2006 — Marked Resolved.
×

Success!

Help @Mr_Initial_Man spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...