joomla 3.1 dropdown in custom component - html

how do I create a dropdown list in joomla 3.1 for a custom component. I try to create custom fields and I would like to use joomlas dropdown with search
my get input method looks
public function getInput() {
$jinput = JFactory::getApplication()->input;
$sub_id = $jinput->get('sub_id');
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('*')
->from('#__unis_faculties')
//->join('#__unis_subjects')
->order('faculty_name');
$db->setQuery($query);
$rows = $db->loadObjectList();
if (isset($sub_id)) {
$actual = $db->getQuery(true)
->select('f.id, f.faculty_name')
->from('#__unis_faculties AS f')
->join('LEFT', '#__unis_subjects AS s ON f.id = s.faculty')
->where('f.id = ' . $sub_id);
$db->setQuery($actual);
$actual_row = $db->loadRow();
}
$html = '';
$html .= '<div class="span12 input-prepend">
<span class="add-on">€ </span>
<input class="span4" name="price" id="price" type="text" />
</div>';
$html .= '<field name="" type="list" default="" label="Select an option" description=""><select>';
foreach ($rows as $row) {
$html .= '<option ' . "selected" ? $row->id = $actual_row->id : '' . 'value="' . $row->id . '" >' . $row->faculty_name . '</option>';
}
$html .= '</select></field>';
return $html;
}
but this does not outputs the desired result, the list won't shows up
the actual code is producing the following dropdown but without to show the elements

Related

Storing Pictures To mysql Using Laravel

I'm trying to store some upload pictures to my database using laravel. Everything goes well, everything got stored, but for the file, they keep storing a bin file of 38B, I've tried reading it to .Txt files and it has a path to /Applications/MAMP/tmp/php/phpUzMXbn.
Here is my function code :
Route::post('/FruitCreate',function(Request $request){
$fruit = new fruit;
$fruit->name = $request->name;
$fruit->price = $request->price;
$fruit->picture = $request->image;
$fruit->save();
return redirect('FruitsChangingPricePanel');
My form blade :
<form enctype="multipart/form-data" method="POST" action="{{ url('FruitCreate') }}" >
{{ csrf_field() }}
<input type="text" name='name'>
<input type="text" name='price'>
<input type="hidden" name="MAX_FILE_SIZE" value="30000000" />
<input type="file" name='image'>
<button type='submit'> submit </button>
thank u For Your Help !!
You can do may be something like that:
$file = $request->file('image');
$imageContent = $file->openFile()->fread($file->getSize());
$fruit = new fruit; $fruit>picture = $imageContent; $fruit>save();
Note: Your column type must be Blob
because you are trying to save directly bin.
try this one
$file = Input::file('file');
$destinationPath = public_path(). '/uploads/';
$filename = $file->getClientOriginalName();
$file->move($destinationPath, $filename);
echo $filename;
//echo '<img src="uploads/'. $filename . '"/>';
$user = ImageTest::create([
'filename' => $filename,
]);
Firstly, you should get your image and then store it to public/uploads/fruits folder.And after that, you are saving the path to your picture to DB.
$fruit = new fruit;
$fruit->name = $request->name;
$fruit->price = $request->price;
if ($request->has('image')) {
if (!file_exists(public_path('uploads/fruits/'))) {
mkdir(public_path('uploads/fruits/'));
}
if (!file_exists(public_path('uploads/fruits/' . date('FY') . '/'))) {
mkdir(public_path('uploads/fruits/' . date('FY') . '/'));
}
$image = $request->file('image');
$filename = public_path('uploads').'/fruits/' . date('FY') . '/' . str_random() . '.' . $image->guessExtension();
\Image::make($image->getRealPath())->encode('jpg')->resize(220, 220)->put($filename);
$fruit->picture = $filename;
}
$fruit->save();

How can I group subtopics into topics in this MySQL statement?

I've tried GROUP BY with my data below but it only brings back one subtopic. How can I return all the subtopics and organise them under each topic without the topic_name appearing with each subtopic_name.
Edit: Included a screenshot of the page and here is the PHP used:
<ul class="topics-list">
<?php
foreach ($data as $key){
foreach ($key as $item){
$topic_name = $item['topic_name'];
$subtopic_name = ucwords($item['subtopic_name']);
?>
<div class="the_topic">
<h2 class="topic_change"><?php echo $topic_name; ?></h2>
<ul><li class="subtopic_name"><h3><?php echo $subtopic_name; ?></h3></li></ul>
<hr />
</div>
<?php } ?>
<?php } ?>
</ul>
You could use GROUP_CONCAT() to concatenate all subtopics into one string per topic, and then parse the string in your application code.
SELECT topic_name, GROUP_CONCAT(subtopic_name DELIMITER '§§§') as subtopic_names
FROM questions2
GROUP BY topic_name
But i do not recommend that, because you will get in troubles, if a subtopic contains your delimiter. I would just use your second query and group the result in the application code.
PHP code would look something like:
// group the data
$groupedData = array();
foreach ($data as $item) {
$topic_name = $item['topic_name'];
$subtopic_name = ucwords($item['subtopic_name']);
$groupedData[$topic_name][] = $subtopic_name;
}
// grouped output
foreach ($groupedData as $topic_name => $subtopic_names) {
echo '<div class="the_topic">';
echo '<h2 class="topic_change">' . $topic_name . '</h2><ul>';
foreach ($subtopic_names as $subtopic_name) {
echo '<li class="subtopic_name"><a href="#" data-toggle="modal" data-target="#lvlModal"><h3>';
echo $subtopic_name;
echo '</h3></a></li>';
}
echo '</ul><hr /></div>';
}

Yii2 preselect radiobutton value

I know I can use
<?= $form ->field($model, 'subject')
->textInput(array('value' => 'VALUE'))
->label('Titel'); ?>
to prefill a Textfield, but how can I do it for a radioList?
<?= $form ->field($model, 'locations')
->radioList($regionen)
->label('Regionen');
I could use ->textInput again but this transforms the whole List into a single Textfield
Alternativly: Is there a better way to modify a database record? Currently I'm trying to set all values into a new form.
Put the value that you want selected in the locations attribute of your $model and after rendering, it will be pre-selected in the radio list. That is:
$model->locations = ....
I assume that locations is a foreign key to some other table (or maybe a fixed list of strings).
Referring the documentation :
Pass the second parameter, options[] to radioList()
$options = [
'item' => function($index, $label, $name, $checked, $value) {
// check if the radio button is already selected
$checked = ($checked) ? 'checked' : '';
$return = '<label class="radio-inline">';
$return .= '<input type="radio" name="' . $name . '" value="' . $value . '" ' . $checked . '>';
$return .= $label;
$return .= '</label>';
return $return;
}
]
<?= $form->field($model, 'locations')
->radioList($regionen, $options)
->label('Regionen');
Hope this helps..

Wordpress: previous_post_link() sits on top, after div "entry-content", no matter where I place it

I have installed a plugin which is custom post type, I am trying to use the previous_post_link() and next_post_link() to get previous and next posts.
It is working fine but the only problem is that I am placing it in my 4th div container where as it always sits on top of page right after div "entry-content".
Is it a known issue?
Here is the piece of code:
function some_function () {
global $post;
if ('team' == get_post_type() && is_single() && in_the_loop()) {
$fields = WPMTPv2_OPTIONS()->fields;
$meta = WPMTPv2_FIELDS($post->ID);
$tmp = '<div id="wpmtp-single-wrap">';
$tmp .= '<div class="wpmtp-vcard">';
$tmp .= '<div class="wpmtp-vcard-left">';
$tmp .= wpmtpv2_featured_img($post->ID);
$previous = previous_post_link('%link', '<div class="wpmtp-gonext">view next</div>');
$next = next_post_link('%link', '<div class="wpmtp-goback">go back</div>');
// $tmp .= '<div class="wpmtp-goback">go back</div>';
// $tmp .= '<div class="wpmtp-gonext">view next</div>';
$tmp .= $previous;
$tmp .= $next;
$tmp .= '</div>';
...........
..........
..........
........
return $tmp;
}
If I place the commented html code instead or previous and next functions, it works fine. Which mean that html and css are right in place, and the problem is in the functions I guess.
And this is what I get after inspecting it in firebug:
<article .....>
<h2 .....></h2>
<div class="meta"></div>
<div class="entry-content">
<a href="link to next" rel="prev">
<div class="wpmtp-gonext">view next</div>
</a>
<a href="link to previous" rel="next">
<div class="wpmtp-goback">go back</div>
</a>
<div id="wpmtp-single-wrap">
<div class="wpmtp-vcard">
<div class="wpmtp-vcard-left">
.....
....
....
....
try this code:
<?php
function some_function () {
global $post;
if ('team' == get_post_type() && is_single() && in_the_loop()) {
$fields = WPMTPv2_OPTIONS()->fields;
$meta = WPMTPv2_FIELDS($post->ID);
?>
<div id="wpmtp-single-wrap">
<div class="wpmtp-vcard">
<div class="wpmtp-vcard-left">
<?php echo wpmtpv2_featured_img($post->ID); ?>
<div class="wpmtp-goback"><?php previous_post_link( '%link', __( ' go back', 'twentyeleven' ),TRUE ); ?></div>
<div class="wpmtp-gonext"><?php next_post_link( '%link', __( 'view next', 'twentyeleven' ),TRUE ); ?></div>
<?php
// replace **twentyeleven** with your theme name
//or try with this line
//previous_post_link('%link', '<div class="wpmtp-gonext">view next</div>');
//next_post_link('%link', '<div class="wpmtp-goback">go back</div>');
?>
</div>
<?php
.........
.........
........
return $tmp;
}
or best to try this plugin : wp-pagenavi
This plugin provides the wp_pagenavi() template tag which generates fancy pagination links.
thanks

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

I'm having a problem regarding Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING. I tried every solution in available online but still I got the same error over and over again.
So the problem is: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\wamp\www\RedCross\load.php on line 25
load.php
<?php
include_once('connect.php');
$EventNum = $_POST['ename'];
//die('You sent: ' . $selStudent);
//Run DB query
$query = "SELECT Price FROM events WHERE EventID = '".$EventNum."' ";
$result = mysql_query($query) or die('Fn another_php_file.php ERROR: ' . mysql_error());
$num_rows_returned = mysql_num_rows($result);
//die('Query returned ' . $num_rows_returned . ' rows.');
//Prepare response html markup
$r = "
<div class='control-group'>
<label class='control-label' for='price'>Price </label>
<div class='controls'>
";
//Parse mysql results and create response string. Response can be an html table, a full page, or just a few characters
if ($num_rows_returned > 0) {
while ($row = mysql_fetch_array($result)) {
$r = $r . "<input type='text' name='price' id='price' class='input-xlarge' value = " . $row['Price'] . " readonly>";
}
$r = $r . "<center>
<button type='submit' class='btn btn-large btn- danger' name='submit' id='submit'>Join!</button>
</center>";
//The response echoed below will be inserted into the
echo $r;
} else {
$r = '<p>sorry there is no available staff for this</p>';
// $r = $r . '</select><input type="submit" name ="go" value="press me">';
$r = $r . '</div></div>';
//The response echoed below will be inserted into the
echo $r;
}
//Add this extra button for fun
?>
Line 25 is this code:
Even though I put spaces before it making this line not in line 25 still the error is in line 25.
Please help.
Change the code in line 25 to line below and test:
$r = $r . '<input type="text" name="price" id="price" class="input-xlarge" value = ' . $row["Price"] . ' readonly>';