News:

Wondering if this will always be free?  See why free is better.

Main Menu

Help with ssi_boardNews array

Started by Trekkie101, July 24, 2005, 02:32:26 PM

Previous topic - Next topic

Trekkie101

Im using the following code

<?php
require("/home/ezine56/public_html/beta/forum/SSI.php");

$array ssi_boardNews(18.0nullnullnull'array');
echo 
'<form action="test.php" method="post" name="messageidnumber">
<select name="messageidnumber">'
;
foreach ($array as $news)
{
echo '
<br /><option value="'
,$news['id'],'">'$news['subject']
,if (!
$news['is_last']);
echo '</option>';
}
echo 
'</option>
<input type="submit" value="Go" />
</form>'
;

?>


Which creates a drop down form you can click go and it sends a variable to page via "post" but this just returns me

Parse error: parse error, unexpected T_IF in /home/ezine56/public_html/beta/forum/newsarray.php on line 10


kegobeer

<br /><option value="',$news['id'],'">', $news['subject']
,if (!$news['is_last']);


You can't do that.  If/then branches can't be added to an echo statement.  I think this is what you are looking for:

<?php
require("/home/ezine56/public_html/beta/forum/SSI.php");

$array ssi_boardNews(18.0nullnullnull'array');
echo 
'<form action="test.php" method="post" name="messageidnumber">
<select name="messageidnumber">'
;
foreach (
$array as $news)
{
  echo 
'<option value="',$news['id'],'">'$news['subject'], '</option>';
}
echo 
'</select>
<input type="submit" value="Go" />
</form>'
;

?>


If you are looking for XHTML compliance, all <option> tags need a closing </option>, so there's no need for a conditional statement.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Trekkie101

#2
Thank you so much, ive been working at that for ages.

http://www.ihsezine.com/beta/forum/newsarray.php

But if you try that, it doesnt seem to want to allow any to work minus the last option, any idea why?

Edit: yes permissions are set right.

kegobeer

Post test.php here so I can see it.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Trekkie101

#4
Very simple

<?php
require("/home/ezine56/public_html/beta/forum/SSI.php");
ssi_grabMessage($messageidnumber);
?>


Edit: heres the ssi_grabMessage function incase you want it

function ssi_grabMessage($message_id = null, $output_method = 'echo') {
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
loadLanguage('Stats');

if ($message_id !== null) $message_id = (int) $message_id;
elseif (isset($_GET['ID_MSG'])) $message_id = (int) $_GET['ID_MSG'];
else die("Please specify a message id");

$request = db_query("
SELECT m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName,
m.posterTime, m.ID_MSG, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, b.name
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}boards as b
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG = $message_id
AND m.ID_TOPIC = t.ID_TOPIC
AND t.ID_BOARD = b.ID_BOARD
AND FIND_IN_SET(-1, b.memberGroups)
", __FILE__, __LINE__);
$return = array();

if (mysql_num_rows($request) == 0) {
if ($output_method == 'echo') die($txt['smf_news_error2']);
else return;
}

$row = mysql_fetch_assoc($request);
$row['body'] = doUBBC($row['body'], $row['smileysEnabled']);

censorText($row['subject']);
censorText($row['body']);

$return[] = array(
'icon' => '<img src="' . $settings['images_url'] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'] . '">Read More...',
'new_comment' => '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.0">Reply</a>',
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => !empty($row['ID_MEMBER']) ? $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] : '',
'link' => !empty($row['ID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName']
),
);
mysql_free_result($request);

if ($output_method != 'echo') return $return;

foreach ($return as $news)
echo '
<table border="0" width="100%" align="center" class="smfNews">
<tr><td>', $news['icon'], ' <b>', $news['subject'], '</b><span class="smaller"><br />', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '<br /><br /></span></td></tr>
<tr><td>', $news['body'], '<br /><br /></td></tr>
<tr><td>', $news['link'], ' | ', $news['new_comment'], '</td></tr>
</table>
';

}

kegobeer

#5
You have to grab the $_POST['messageidnumber'] variable.

<?php
require("/home/ezine56/public_html/beta/forum/SSI.php");
if (isset(
$_POST['messageidnumber'])) {
  
$messageidnumber $_POST['messageidnumber'];
  
ssi_grabMessage($messageidnumber);
}
?>
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Trekkie101

#6
QuoteParse error: parse error, unexpected T_ISSET, expecting '(' in /home/ezine56/public_html/beta/forum/test.php on line 3

Sorry about this, its another thing im trying to learn php.

Edit:

I tried

Quote<?php
require("/home/ezine56/public_html/beta/forum/SSI.php");
if (isset($_POST['messageidnumber'])) {
  $messageidnumber = $_POST['messageidnumber'];
  ssi_grabMessage($messageidnumber);
}
?>
but it returns

QuoteYou cannot specify a board that doesn't allow guests. Please check the board ID before trying again.

kegobeer

Before ssi_grabMessage, add this

echo $messageidnumber . '<br>';

Post what number(s) you are getting.  Also, why not use ssi_boardNews?
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Trekkie101

I see whats wrong, the Topic ID is being used when used in boardNews but the message ID is completely different.

I think im going to switch it over to boardNews.

But, its only to grab one topic, not them all, and it has to be able to pull say the third topic in the board while ignoring the first two.


kegobeer

You are using mem in your query, but it isn't defined anywhere.  That's probably causing your problem.

[edit]I see it now.  Scratch that.[/edit]
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Trekkie101

Thank you so much for your help!

  echo '<option value="',$news['id'],'">', $news['subject'], '</option>';
}


I changed $news['id] to $news['message_id'] and it works exactly like a good little script.

Thank you so much again!

kegobeer

It's always the little things, isn't it?  Glad to help.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Trekkie101

Quote from: kegobeer on July 24, 2005, 04:20:25 PM
It's always the little things, isn't it?  Glad to help.
Yeah, 1 word, lol, anyway thanks.

Its funny, the bit that takes the longest to code and get right, always has a small job.

But none the less, I love it

Thanks a bunch!

Advertisement: