/    Sign up×
Community /Pin to ProfileBookmark

Would this work?

I’m trying to get the topics data table from my forum’s MySQL database fed onto my website.

I went into the PhpMyAdmin and I changed the SQL code of the base to PHP and got this:

[code=php]$sql = ‘SELECT * FROM `forums_topics` LIMIT 0, 30 ‘; [/code]

I don’t know much about PHP, but I’ve seen it alot, so I took a guess at how to implement it into my site.
Here’s what I did:

[code=php]<?php

$sql = ‘SELECT * FROM `forums_topics` LIMIT 0, 30 ‘;

?>[/code]

But whatever code that is in the section that I want the feed to be in has to be in between <li></li> tags, and I do not know how to put those into PHP, which is what I’m assuming is making the above code not work.

What happens is just a “.” where the feed should be.

Does anyone know if this is the problem, and if so, how can I fix it?

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@maneetpuriSep 05.2009 — Hi,

The code you have added just constructs the query, after it you will have to execute it, get the result returned in an array and then run a while loop or foreach on this array to populate the <li>.

Hope this helps.

Cheers,

~Maneet
Copy linkTweet thisAlerts:
@CuppyTeaSep 05.2009 — [url=http://uk2.php.net/manual/en/function.mysql-fetch-assoc.php]This page should help you[/url].

Check out the page example.
Copy linkTweet thisAlerts:
@poker158149authorSep 05.2009 — Alright, I used the example on the page and edited everything I could find.

What do I have to put as my row? Because I think I'm getting my rows and columns mixed up. Because when I try to run this, it shows me this:

[CODE]No rows found, nothing to print, so am exiting[/CODE]


Here is the code I'm currently using:


[code=php]<?php

$conn = mysql_connect("localhost", "ashint_cn", "********");

if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}

if (!mysql_select_db("ashint_forums")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}

$sql = "SELECT title as title
FROM forums_topics
WHERE title = 1";

$result = mysql_query($sql);

if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}

if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print, so am exiting";
exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
echo $row["title"];
}

mysql_free_result($result);

?>[/code]



Please note, my password is not actually 8 stars.
Copy linkTweet thisAlerts:
@criterion9Sep 05.2009 — Do you have any data in the database to query?
Copy linkTweet thisAlerts:
@poker158149authorSep 05.2009 — Yes, I'm trying to query my recent topics posted and there are 4 topics in the database. I'm thinking I'm just putting the wrong queries in the code
Copy linkTweet thisAlerts:
@welshSep 05.2009 — most likely the problem is your query, so try changing it to:
[code=php]$sql = "SELECT * FROM forums_topics ORDER BY insert_here DESC LIMIT 4"; [/code]
change the "insert_here" in the query to something like an id for the table or a date so it will pull the most 4 more recent from the table.
Copy linkTweet thisAlerts:
@poker158149authorSep 06.2009 — Wow, that actually worked. Thanks alot!

Now the only problem is it comes out like this:

[CODE]Windows 7Snow Leopard is here!Instant Messaging....Advertising Video[/CODE]

While it should actually show like this:

[CODE]Windows 7
Snow Leopard is here!
Instant Messaging....
Advertising Video[/CODE]
Copy linkTweet thisAlerts:
@criterion9Sep 06.2009 — change this:
[code=php]
echo $row["title"];
[/code]

to:
[code=php]
echo $row["title"]."<br />";
[/code]
Copy linkTweet thisAlerts:
@poker158149authorSep 06.2009 — Ah, thank you again!

Now, another problem. How can I link them to the actual post?
Copy linkTweet thisAlerts:
@welshSep 06.2009 — [code=php]echo $row["title"]."<br />"; [/code]
to
[code=php]echo '<a href="link.php">' . $row['title'] . '</a><br />'[/code]
is the default thing, however im not sure what the url up top shows as, im guessing it would be like yourwebsite.com/forum/showthread.php?t=1234 so then assuming t is like the column id then it would be:
[code=php]echo '<a href="yourwebsite.com/forum/showthread.php?t=' . $row['id'] . '">' . $row['title'] . '</a><br />'[/code]
Copy linkTweet thisAlerts:
@poker158149authorSep 06.2009 — You are a god. Thank you so much!
×

Success!

Help @poker158149 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...