site database driven with 2.0 RC1.2

Started by mandukar, August 13, 2009, 07:12:17 AM

Previous topic - Next topic

mandukar

Hi all, I have a problem, my site was previously running 1.1.10 and what I was my content for the main part of the site http://pagancentral.org was calling content from threads using this code.


<?php if ($id<>"") { echo "<h1>".$moot['subject']."</h1>"; echo bbcode($moot['body']); echo "<p style='line-height:40px'><a href='moots.php'>Back to list of Moots</a></p>"; } else { echo "<h1><span>Pagan </span>Central Moots</h1><ul> <p>A Moot is essentially a social meeting for Pagans, they can be held in any venue but most of the Pagan Central Moots are held in pubs. Below are a list of moots currently in association with Pagan Central:</p>"; $con = mysql_connect("localhost","bla","bla"); if (!$con) {   die('Could not connect: ' . mysql_error());   } mysql_select_db("bla", $con); $result = mysql_query("SELECT * FROM `smf_messages` WHERE `ID_BOARD` = 11 AND `subject` LIKE '%Moot%' AND `subject` NOT LIKE '%Re:%' OR `ID_BOARD` = 11 AND `subject` LIKE '%Gathering%' AND `subject` NOT LIKE '%Re:%'"); while($row = mysql_fetch_array($result))   {   echo "<li id='subnav'><a href='moots.php?id=".$row['ID_TOPIC']."'>" . $row['subject'] . "</a></li>"; } mysql_close($con);  echo"</ul>"; } ?>
now for some reason the ifnrmation doesn't get displayed I can only asume that the database has changed some way? also on my events page I get a error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/paganc/public_html/events.php on line 51

using this code
<?php echo "<h1><span>Pagan </span>Central Events</h1> <p>Below is a summary of the next months events, for a complete calendar of events <a href='http://pagancentral.org/smf/index.php?action=calendar'>click here</a>.</p><table border='0' cellpadding='7' cellspacing='7'>"; $con = mysql_connect("localhost","bla","bla"); if (!$con) {   die('Could not connect: ' . mysql_error());   } mysql_select_db("bla", $con); $result = mysql_query("SELECT DATE_FORMAT(smf_calendar.startDate, '%W <br>%D %M %y') AS startDate, smf_calendar.ID_TOPIC, smf_topics.ID_FIRST_MSG, smf_messages.subject, CURDATE() FROM smf_calendar INNER JOIN smf_topicsON smf_calendar.ID_TOPIC=smf_topics.ID_TOPIC INNER JOIN smf_messagesON smf_topics.ID_FIRST_MSG=smf_messages.ID_MSG WHERE smf_calendar.startDate >= CURDATE() AND smf_calendar.startDate <= DATE_ADD(curdate(), INTERVAL 1 MONTH) ORDER BY smf_calendar.startDate ASC"); while($row = mysql_fetch_array($result))   {   echo "<tr height='40'><td width='100'>".$row['startDate']."</td><td><a href='http://pagancentral.org/smf/index.php?topic=".$row['ID_TOPIC']."'>" . $row['subject'] . "</a></td></tr>"; } mysql_close($con);  echo"</table>"; ?>

while($row = mysql_fetch_array($result)) is on line 51

Arantor

Well, the database has changed, though I can't think why the first query fails. Is the table prefix definitely smf_ ? Note also that you can likely reduce your query to a smaller one depending on exactly what you're trying to do (remember AND and OR have different priorities)

Note that you shouldn't be using mysql_fetch_array anyway but instead mysql_fetch_assoc(), since that actually halves the memory use by only adding the associative entries ($row['ID_TOPIC'] etc) without adding the indexed entries ($row[0] as well as $row['ID_TOPIC']) but that shouldn't be the cause of the error.

You can always use mysql_error() to confirm the error message, though for the second I'd suggest that the calendar's column is now start_date not startDate if it's anything like the rest of 2.0.
Holder of controversial views, all of which my own.


mandukar

yeah the prefix defently starts with smf_

I still get the error on the calendar page.

mandukar

ok i got the calander page working, i missed one of the start_dates hehe,

mandukar

with the first one do u mean i should take out the id topic?

mandukar

#5
could you give me an example of what you mean on the first code please?

basicly what i'm trying to do with the first code is when a user clicks on the link in my menu, it gives them a short discription. at the moment when the user clicks it, it gives the list of the links instead.

Arantor

You call mysql_fetch_array, right? And you have 'ID_TOPIC' and 'subject' in the query, with ID_TOPIC being 1 and subject being 'Hello!'.

$row = mysql_fetch_assoc(...) will return:
$row['ID_TOPIC'] = 1;
$row['subject'] = 'Hello!';

As you can see, you're creating each entry in $row twice. Just switch mysql_fetch_array() to mysql_fetch_assoc().

And please, do not quadruple post, there is an edit button. Also please note that we're all volunteers here - we normally ask that bumps are done after no less than 24 hours.
Holder of controversial views, all of which my own.


mandukar

ok i'm sorry about the 3 time posting, i got exited,

I replaced the array with assoc but still get the error

Arantor

Like I said, that wouldn't solve the error, it was something I mentioned in passing.

Add this after the mysql_query() call for now:
echo mysql_error();

What does it say?
Holder of controversial views, all of which my own.


mandukar

ahh i got it to work, i had to put the Id_topic and id board to lowercase. thanks for your help :D

Advertisement: